I'm following this example from Adafruit that shows how to program an AVR such as ATMega328P from a Raspberry Pi, using the AVR's ICSP pins.
I run all the steps and it is working fine except a single issue with the clock. I'm testing the traditional blink example from Arduino IDE, that blinks an LED with intervals of 1 second. The problem is that instead of 1 second, my LED is blinking every 15 seconds! Any idea of what might be causing such a problem?
I using Raspberry 4 with Raspbian Buster and an ATMega328P. This is the code I'm compiling with Arduino IDE:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
My guess is that the 15 seconds is really 16, and you have changed the fuse settings so the processor is not running of a 16Mhz external clock source, but is running on some internal 1MHz.
Use avrdude to see what your current fuses are. The tutorial gave you a command which gives the fuse settings.
You want to see this
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as 5
If that's not what you have, you will have to reburn the fuse settings.
I use the "burn bootloader" option in the Arduino IDE to set the clock fuses. You only have to do it once with a new chip so it's not too much trouble.
Yes, avrdude final output is not exactly that but:
avrdude: verifying ...
avrdude: 1052 bytes of flash verified
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:62)
avrdude done. Thank you.
How do I reset the fuses? I can't use the "Burn the bootloader" option, because I just have a Raspi Pi and a ATMega328P chip (with the 16MHz crystal and two capacitors)
miguelwon:
I can't use the "Burn the bootloader" option, because I just have a Raspi Pi and a ATMega328P chip (with the 16MHz crystal and two capacitors)
How are you connecting the Atmega 328 to the RPi ?
I have an 8Mhz Atmega 328 on stripboard that I use for uploading programs using ICSP to various chips. The Atmega 328 has the standard ArduinoISP program on it. Sometimes it is useful to load one or other of Nick Gammon's diagnostic programs to the Atmega 328.
Ok, I think I have it working properly now. According to this post "0xFD is now the same as 0x05 used to be." and so that part is ok. For the other two I just reseted the fuses with: