0
\$\begingroup\$

I use an Arduino Mega to program an AT28C256 by using this code [1], but there is a weird issue!

The Arduino's pin 41 is connected to the AT28C256's pin 16 which is I/O 4. It works without any problem up to 27-30 bytes, but afterwards it goes low!

For example, I tried to write 0xEA (11101010) to the first 200 addresses, first 29 bytes were fine, but after that all bytes were 0xE2 which means 11100010. I tired to program different EEPROMs with different data, e.g. 0xFF (11111111) but again after 30 bytes it was all 0xF7 (11110111).

I double checked connections and the circuit, everything seems to be fine (otherwise how could the first few bytes be correct?). I also captured the data with a logic analyzer, the capture shows this data line goes low after few bytes.

What could be wrong?

[1] https://create.arduino.cc/editor/albs_br/94b6f3f5-413d-4714-80dc-836bf5b3705c/preview

\$\endgroup\$
2
  • \$\begingroup\$ _" I also captured the data with a logic analyzer, the capture shows this data line goes low after few bytes" - can you show us an example capture (with EEPROM control lines also captured)? What happens if you use a different pin on the Arduino? \$\endgroup\$ Commented Apr 10, 2021 at 21:43
  • \$\begingroup\$ The code does not follow the standard programming algorithm of an EEPROM but just blindly programs a byte without ever polling for the end of the write cycle (by checking bit 7 of the data read back from the EEPROM and comparing it to bit 7 of the written data). It just assumes the write cycle is finished within 1 ms and proceeds to programming the next byte. As some EEPROMS have a maximum write cycle time larger than 1 ms, this can fail. You shoud either implement a polling algorithm (preferred) or wait the maximum amount of time allowed for a write cycle (~5ms but dependent on your device). \$\endgroup\$
    – StarCat
    Commented Apr 11, 2021 at 7:37

1 Answer 1

2
\$\begingroup\$

It looks like the code you linked to does not follow the standard programming algorithm of an EEPROM but just blindly programs a byte without ever polling for the end of the write cycle. The code waits 1 ms after programming every byte, but the write cycle time of an EEPROM can be larger than that see the AT28C256 datasheet, page 9.

Normally you check for the end of the EEPROM write cycle by reading back data from the EEPROM and checking if bit 7 of the data read back is equal to bit 7 of the data being written. This is explained in the data sheet, the I/O7 !DATA polling algorithm, page 1.

enter image description here

Your code just assumes the write cycle is finished within 1 ms (the delay(1) between the writeEnable() and chipDisable() calls and proceeds to programming the next byte. As some EEPROMs have a maximum write cycle time larger than 1 ms, this can fail.

enter image description here

The solution is to either implement a polling algorithm, which is preferred because it's faster and more reliable but it's also more complicated. The alternative is to wait for the maximum amount of time allowed for a write cycle (~10ms but this is dependent on your device).

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the explanation. Considering the issue is the write process as you explained, why only one bit (I/O4) is wrong, and only after successfully writing a couple of bytes? My point is if this issue is caused by the wrong implementation of the write process, corrupted bytes should not occur more random, and different corrupted bits? \$\endgroup\$
    – Sina
    Commented Apr 11, 2021 at 9:03
  • \$\begingroup\$ That might be due to the variation within a single device. There's no particular reason it should be I/O4 and with different devices it might be another I/O pin, maybe several or none at all. The fact is that the code assumes certain timings and does not use one of the algorithms recommended by the manufacturer, so it might work, it might not work, or it might work some of the time. Best is to stick with what the datasheet recommends.That said, the problem might also be somewhere else, like a marginal connection within your setup. \$\endgroup\$
    – StarCat
    Commented Apr 11, 2021 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.