Trouble reading/writing EEPROM via avrdude
ok, have mega2560's need read , write eeprom computer - seems perfect job avrdude, supports exact case, getting strange results avrdude. short of it, can read/write eeprom inside sketches without problems, reading avrdude gets me corrupt data. test this, wrote simple sketch wipes clean eeprom, writes test data , dumps serial in hexdump-like fashion:
this should , gives me like:
so far good. dump same data using avrdude , dump out:
as see, things got weird. getting every other 8 bytes of data.... , repeat
now, aware optiboot cannot handle eeprom, made sure not running it. running standard bootloader, sure, re-burned bootloader using this: https://github.com/nickgammon/arduino_sketches/tree/master/atmega_board_programmer
what missing here?
thanks,
-hh
code: [select]
#include <eeprom.h>
void eepromdump() {
char buff[8];
int counter = 0;
byte data = 0;
serial.write("eeprom contents:\n");
(int = 0; < 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");
(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 should , gives me like:
code: [select]
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 00's>
so far good. dump same data using avrdude , dump out:
code: [select]
$ 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 see, things got weird. getting every other 8 bytes of data.... , repeat
now, aware optiboot cannot handle eeprom, made sure not running it. running standard bootloader, sure, re-burned bootloader using this: https://github.com/nickgammon/arduino_sketches/tree/master/atmega_board_programmer
what missing here?
thanks,
-hh
somewhere along line looks it's losing high bit in address, halfway through , starts reading start again... happen if use icsp programmer instead of doing through bootloader? not surprised if bootloader has bug around here - doesn't jump out @ me looking @ code, like, eeprom write section (though not read section) has comment indicating wasn't tested author.
(also - "empty" eeprom cell 0xff, not 0x00 - if chip erase, start out 1's, not 0's - same flash)
(also - "empty" eeprom cell 0xff, not 0x00 - if chip erase, start out 1's, not 0's - same flash)
Arduino Forum > Using Arduino > Microcontrollers > Trouble reading/writing EEPROM via avrdude
arduino
Comments
Post a Comment