Programmer Setup
Published Thursday, November 14, 2013 by Matt Kelly in Electrical Engineering, Motor Testing Station
Building the Circuit
Testing the Programmer
Due to Ubuntu permission settings that I do not understand, I had to prefix all of the following commands with "sudo". This allows avrdude to run with administrator rights.
The first step is to test if avrdude is able to connect to the µC. Plug in the USB cable and type "avrdude" into the command line to see a list of options. Next, determine the type of your programmer. Typing "avrdude -c asdf" will display a list of programmers. The Sainsmart programmer is a "usbasp" programmer. Next, specify the type of microcontroller you are using. Typing "avrdude -p asdf" will display the list of microcontrollers avrdude supports.
Typing "avrdude -c usbasp -p m8" will display the following if avrdude is able to connect to the µC. If you get an error, check the connections between the programmer and the µC. Otherwise we are ready to load the program.
Coding
For now, the only difference between beginner C programs and µC programs are the inputs and outputs. You're probably used to using printf or cout to display output and scanf or cin to take input. Here, our inputs and outputs are high/low states of pins being watched or set. For example, the line of code to turn on an LED connected to PB0 is "PINB = 0x01". Note that this will set B 1-5 to low. AVR C supports logic expressions. To toggle the state of PB0, type "PINB ^= 0x01" (^= is the XOR function).
Programming
We're now ready to load the code onto the µC. Use the following command:
sudo avrdude -c USBasp -p atmega8 -U flash:w:hello.hex:i
You should see the following in the command window:
The µC will begin executing the code immediately!
Subscribe to:
Post Comments (Atom)




0 comments:
Post a Comment