hinata46243 / mega-isp

Automatically exported from code.google.com/p/mega-isp
0 stars 0 forks source link

programming EEPROM not handled correctly - word-wise vs. byte-wise #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. burn some data > 4 bytes to EEPROM using ArduinoISP v4 and e.g. avrdude
an example (intel hex formatted eep) file would contain
:080000008040201008040201F9
:00000001FF
when running some AVR code to read values from EEPROM one will observe that the 
data written to the EEPROM is organized incorrectly.

2. read the EEPROM with another programmer, e.g. myAVR

3. compare results

What is the expected output? What do you see instead?

The above example should put this sequence of bytes into the EEPROM
0b10000000
0b01000000
0b00100000
0b00010000
0b00001000
0b00000100
0b00000010
0b00000001

what the flash actually contains after the write:
0b10000000
0b01000000
0b00100000
0b00010000
0b11111111
0b11111111
0b11111111
0b11111111
0b00001000
0b00000100
0b00000010
0b00000001
0b11111111
0b11111111
0b11111111
0b11111111

The data is complete, but has a wrong organization

What version of the product are you using? On what operating system?
ArduinoISP v4, ATMega8, avrdude on Windows 7. But this is not of any concern

Please provide any additional information below.

The misconception here is that the EEPROM is organized word-wise.
but the ATMega8 datasheet clearly states on page 19 that the EEPROM is 
organized bytewise. Thus multiplying the global variable "here" with two in the 
EEPROM read and write routines causes this bug. I suggest to change these 
functions as follows:

uint8_t write_eeprom(int length) {
  // this writes byte-by-byte,
  // page writing may be faster (4 bytes at a time)
  for (int x = 0; x < length; x++) {
    spi_transaction(0xC0, 0x00, here, buff[x]);
    delay(45);
  } 
  return STK_OK;
}

char eeprom_read_page(int length) {
  for (int x = 0; x < length; x++) {
    uint8_t ee = spi_transaction(0xA0, 0x00, here+x, 0xFF);
    Serial.print((char) ee);
  }
  return STK_OK;
}

worked perfectly for me ;-))

Original issue reported on code.google.com by dilib...@googlemail.com on 24 Mar 2011 at 8:32

GoogleCodeExporter commented 8 years ago
This bug also causes http://code.google.com/p/mega-isp/issues/detail?id=14

Original comment by dilib...@googlemail.com on 25 Mar 2011 at 5:10

GoogleCodeExporter commented 8 years ago
Please try the r12 ArduinoISP.pde available on this project. 
http://code.google.com/p/mega-isp/source/browse/trunk/avrisp/ArduinoISP.pde

'here' is a word address, set by the 'U' command.

Original comment by rsb...@gmail.com on 25 Jun 2011 at 3:22