new to external programmers

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

new to external programmers

Post by dragonuv »

Ive read the instructions on how to use the usbtinyisp on here:

http://www.ladyada.net/learn/avr/
and http://www.ladyada.net/make/usbtinyisp/use.html

but the instructions seem too general (which is good but not for a beginner like me). is there a simple guide that teaches how to write a code to the atmega168 on the arduino? or how to read the code from that chip?

thanks.

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: new to external programmers

Post by mtbf0 »

first try

Code: Select all

avrdude -c usbtiny -p m168 -v
to see if avrdude recognizes your chip.

next, if you've got a brand new chip you'll have to burn the fuses. the fuse settings will depend a whole lot on how your board is setup. as it comes from the factory the chip will be running at 1MHz on its internal oscillator. chances are you'll want to change at least the low fuse byte. to burn the low fuse change the string zz in the following to the fuse settings you require.

Code: Select all

avrdude -c usbtiny -p m168 -u -U lfuse:w:0xzz:m
to burn your program

Code: Select all

avrdude -c usbtiny -p m168 -U flash:w:program.hex

dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

Re: new to external programmers

Post by dragonuv »

thanks, does the arduino need to be powered by the usb cable? and in what direction do i insert the 6 pin-cable of my usbtinyisp to the arduino?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: new to external programmers

Post by Franklin97355 »

Take a look at the schematics of the programmer and the arduino to see how they connect then read the instructions.

dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

Re: new to external programmers

Post by dragonuv »

mtbf0 wrote:to burn your program

Code: Select all

avrdude -c usbtiny -p m168 -U flash:w:program.hex
thanks, i could do the first command you specified here without a problem, the 2nd one i didnt need i guess, im writing directly to the arduino. what language should be the program.hex file? (and where does it have to be located?) does it have to be with the void_start and the void_loop that the arduino has?

thanks.

p.s,
when i typed the command "avrdude -c usbtiny -p m168 -U flash:r:prog.hex:i" to try to read what is on the microcontroller all i got in the file itself is ":00000001FF" is there an option to see the cpp source code?

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: new to external programmers

Post by mtbf0 »

dragonuv wrote:
mtbf0 wrote:to burn your program

Code: Select all

avrdude -c usbtiny -p m168 -U flash:w:program.hex
thanks, i could do the first command you specified here without a problem, the 2nd one i didnt need i guess, im writing directly to the arduino. what language should be the program.hex file?
you write a program in c, assembly, basic, in "arduino", whatever... compile and link it and the hex file is what you've got when you're done
(and where does it have to be located?)
it ought to be in your working directory at the time you summon avrdude
does it have to be with the void_start and the void_loop that the arduino has?
only if you're building it in the arduino environment.
when i typed the command "avrdude -c usbtiny -p m168 -U flash:r:prog.hex:i" to try to read what is on the microcontroller all i got in the file itself is ":00000001FF" is there an option to see the cpp source code?
not a chance. unless you've got the source code lying around.

dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

Re: new to external programmers

Post by dragonuv »

mtbf0 wrote:not a chance. unless you've got the source code lying around.
so why does it have a read option ?

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: new to external programmers

Post by mtbf0 »

dragonuv wrote:
mtbf0 wrote:not a chance. unless you've got the source code lying around.
so why does it have a read option ?
so the binary on the mcu can be compared to the hex file to verify it's validity. so you can retrieve the binary from the chip and copy it to another. because the developers had an extra "r" lying around when they were figuring out upload options.

dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

Re: new to external programmers

Post by dragonuv »

thanks for the great answers :)
when i was studying assembly last year i learned that the computer translates from assembly language into binary and i guess the .hex file contains all the assembly instructions. is it true that a sequence of binary code can be translated into an assembly instruction on any microcontroller ? or each microcontroller has its own sequence of binary code which is translated to an instruction (mov ax,01 for example)?
thanks

p.s.
can any microcontroller be programmed? (not necessarily with avr's, but in general)

The_Don125
 
Posts: 373
Joined: Tue Mar 06, 2007 11:51 pm

Re: new to external programmers

Post by The_Don125 »

Yeah, microcontrollers do need to be programmed to do stuff, though that programming could be hard-coded from the factory and never be able to be changed.

And yes, the binary of the AVR translates directly into assembly instructions. For example, the string

Code: Select all

0C01
corresponds to

Code: Select all

ADD R0, R1

dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

Re: new to external programmers

Post by dragonuv »

my question was that if for example the hex number 0c01 translates to the assembly instruction "ADD R0, R1" on every cpu, but my teacher said its not.
is there a list of each assembly instruction that translates to its equvalent in binary\hex (on avr µ-controllers).
so i can translate in assembly the hex file

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: new to external programmers

Post by mtbf0 »

so, you want to reverse engineer somebody else's device. you're probably not going to have a whole lot of fun unless your a very patient individual. and very motivated.

for the instruction set, see the data sheet for the avr you're dealing with.

then try googling "avr disassembler" or something similar. i make this rather unhelpful suggestion because i've never tried this and can offer no helpful suggestions. when i crave frustration i only have to try getting my own code to work.

even with a disassembled file it may be amusing trying to figure out what's going on, especially if the program was originally written in a higher level language.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”