Programming ATmega328P Target Bd
Revision as of 03:40, 23 March 2019 by U731219879 rc (talk | contribs) (Created page with "Setup '''ATmega328P Target Bd''' at 1MHz and flash the blink program to chip that blinks an LED. <br> '''Prerequisites''': Know how to use '''AVRdude''' with a '''USB program...")
Setup ATmega328P Target Bd at 1MHz and flash the blink program to chip that blinks an LED.
Prerequisites: Know how to use AVRdude with a USB programmer. (usbtiny, usbasp, etc.....) avrdude -p m328p -c usbtiny -v | avrdude -p m328p -c usbasp -P usb -v
- Connect USBtiny to ATmega328P Target Board.
- Test the connection to programmer: avrdude -p m328p -c usbtiny -v
- Connect LED with pull down resistor to Pin D13 on ATmega328P Target bd. (Not needed if using Target Bd built in Yellow LED)
- Open Arduino IDE and change the following settings: Under the Tools tab
Board: ="Arduino/Genunio Uno" Programmer: = "USBtiny or USBasp"
- Copy-Paste/Load BlinkATmega328P.ino Arduino file. (Do not Flash at this time)
/* BlinkATmega328P.ino Turns on an LED for one second, then off for one second, repeatedly. AVRdude Embedded Workshop - Rusty Cain 2018 Demonstrate Changing the Fuse setting using AVRdude. */ #define LED_YELLOW 13 void setup() { pinMode(LED_YELLOW, OUTPUT); // Define pin as output } void loop() { digitalWrite(LED_YELLOW, HIGH); // turn the LED on (HIGH is the voltage level) delay(100); // wait for a second digitalWrite(LED_YELLOW, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second }
- Validate ATmega328P clock speed is set to the 1 MHz default by using the following command for reading fuse settings.
avrdude -p m328p -c usbtiny -v
1 MHz Default Settings: avrdude -p m328p -c usbtiny -v -U lfuse:w:0x62:m -U hfuse:w:0xD9:m -U efuse:w:0xFF:m
- Generate the binary file by selecting under the Sketch Tab: "Export complied Binary"
- Flash the chip by Selecting Upload Using Programmer under Sketch Tab in Arduino IDE.
- Notice the speed of the blinking LED at 1MHz.
- Using AVRDude Set Fuses to 8MHz
8 MHz Settings: avrdude -p m328p -c usbtiny -v -U lfuse:w:0xE2:m -U hfuse:w:0xD6:m -U efuse:w:0xFF:m
- Notice the faster blink rate.
- Using AVRDude Set Fuses to 16MHz. Needs 16MHz external clock which is included on the Target board
16 MHz Settings avrdude -p m328p -c usbtiny -v -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0xFF:m
- Notice the even faster blink rate.
- Using AVRDude Set ATmega328P Chip back to 1MHz
1 MHz Default: avrdude -p m328p -c usbtiny -v -U lfuse:w:0x62:m -U hfuse:w:0xD9:m -U efuse:w:0xFF:m
- Notice the blink rate.
Special Note: Some Arduino libraries are written to only work at 16 MHz. Always check the Fuse setting if devices are not working properly. When changing Fuse setting always ensure the correct Baud Rate for any serial RS232 UART communications.
Examples of Clock fuse setting commands:
1 MHz ATmega328P Default Fuse Settings avrdude -p m328p -c usbtiny -v -U lfuse:w:0x62:m -U hfuse:w:0xD9:m -U efuse:w:0xFF:m 8 MHz Internal clock avrdude -p m328p -c usbtiny -v -U lfuse:w:0xE2:m -U hfuse:w:0xD6:m -U efuse:w:0xFF:m 16 MHz Default avrdude -p m328p -c usbtiny -v -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0xFF:m Arduino Uno: 16 MHz Standard Arduino Uno settings. avrdude -p m328p -c usbtiny -v -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0x05:m = Arduino Uno
Project 1 completed.