Ok, I have Mega2560's that I need to read and eventually write EEPROM from a computer - which seems to be a perfect job for avrdude, which supports this exact case, however I am getting some very strange results from AVRDude. Short of it, I can read/write EEPROM inside my sketches without any problems, but reading from avrdude gets me some corrupt data. To test this, I wrote a very simple sketch that wipes clean EEPROM, writes some test data and then dumps it to serial in a hexdump-like fashion:
#include <EEPROM.h>
void eepromDump() {
char buff[8];
int counter = 0;
byte data = 0;
Serial.write("EEPROM contents:\n");
for (int i = 0; i < 4096 ; i++) {
counter = counter % 16;
if (counter == 0) {
snprintf(buff, 10, "%07X", i);
if (i != 0) {
Serial.println();
}
Serial.print(buff);
}
data = EEPROM.read(i);
snprintf(buff, 4, " %02X", data);
Serial.print(buff);
counter ++;
}
Serial.println();
}
void eepromErase(int start){
Serial.println("Erasing EEPROM");
for (int addr=start; addr <4096; addr++){ EEPROM.update(addr, 0x00); }
}
void setup() {
Serial.begin(115200L);
const char data[63]="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
EEPROM.put(0, data);
eepromErase(64);
eepromDump();
}
void loop() {
}
This does exactly what it should and gives me back something like:
Erasing EEPROM
EEPROM contents:
0000000 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66
0000010 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76
0000020 77 78 79 7A 41 42 43 44 45 46 47 48 49 4A 4B 4C
0000030 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 00 00
0000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...<rest are 00's>
So far so good. Now I dump same data using avrdude and dump it out:
$ avrdude -patmega2560 -cwiring -P /dev/cu.usbmodem1421 -b115200 -D -Ueeprom:r:eeprom.raw:r
...<no error output skipped>...
$ hexdump -C eeprom.raw
00000000 30 31 32 33 34 35 36 37 67 68 69 6a 6b 6c 6d 6e |01234567ghijklmn|
00000010 77 78 79 7a 41 42 43 44 4d 4e 4f 50 51 52 53 54 |wxyzABCDMNOPQRST|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000800 30 31 32 33 34 35 36 37 67 68 69 6a 6b 6c 6d 6e |01234567ghijklmn|
00000810 77 78 79 7a 41 42 43 44 4d 4e 4f 50 51 52 53 54 |wxyzABCDMNOPQRST|
00000820 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
As you see, this is where things got weird. I am getting every other 8 bytes of data.... and they repeat
Now, I am aware that Optiboot cannot handle EEPROM, but I made sure I am not running it. I am running the standard bootloader, but just to be sure, I re-burned the bootloader using this: arduino_sketches/Atmega_Board_Programmer at master · nickgammon/arduino_sketches · GitHub
What am I missing here?
Thanks,
-HH