Ghostbird / Arduino_EEPROM_RW

Sketch turns Arduino Serial into interactive command line interface for reading and writing T24C02A I²C EEPROM it has partial support for T24C04A, T24C08A and T24C16A EEPROMS
9 stars 3 forks source link

This manual is released by the author into the public domain.

T24C02A EEPROM set-up:

Arduino set-up:

  1. Open the Arduino IDE.
  2. Connect Arduino (I used USB).
  3. Choose correct board and serial port in Arduino IDE.
  4. Upload code to Arduino using the IDE.
  5. Open serial console (Ctrl+Shift+M).
  6. The board waits 4 seconds after Arduino reset (end of upload).
  7. Then it promps for I²C address.
    • If you do not see this prompt, just enter the address.
    • If you don't know the address, enter the character 'P'.

Getting started:

If you opened the serial console soon enough, you'll be prompted for an I²C address or a 'P'. If you did not open the serial console within four seconds after the Arduino reset, you will not see the prompt, but the Arduino will still patiently wait for your input.

Enter the address, or the character 'P'.

Setting the I²C address:

The Arduino wire library works with 7-bit I²C adresses.

The Arduino Serial library can easily parse decimal values, not hex codes. Therefore the default T24C02A address 0xA0 is rendered thus:

  1. Right-shift one bit to get 7-bit address: 0xA0 >> 1 → 0x50
  2. Convert to decimal: 0x50 → 5×16 + 0 = 80

If you have a T24C04A, T24C08A or T24C16A, you can change addresses later to write to other memory pages.

Polling the I²C bus:

If you entered the character 'P', the Arduino will poll all 128 possible addresses on the I²C bus. It wil show you the address the devices that answered, and their answers.

The main menu:

Once you have successfully entered an address, you will arrive in the main shell menu.

You will be asked for a command char:

R — Read
W — Write
S — Set I²C address
P — Poll the I²C bus.

S is useful if you set the I2C address wrong, have multiple EEPROMs or have a T24C04A, T24C08A or T24C16A IC.

Reading:

  1. Follow the instruction:
    • Enter the start address for the read.
    • Enter the number of bytes to be read.
  2. The device will print all characters on a single line.
  3. Followed by a line of statistics.
    • Optionally followed by a line indicating an error.

Writing:

  1. Follow the instruction:
  2. Enter the start address for the write.
  3. Enter the string to be written.
    • Escape numerical ASCII representations of characters by prefixing them with an @.
    • @64 is the @ character itself, in case you want to write an actual @.
  4. The device will print each character submitted to the device.
  5. The device will print a human readable error message for each unsuccessful write.
    • The device will retransmit (including reprint of) the character up to NUM_TRIES times.
    • NUM_TRIES is set to 10 in the code by default.

After ten failed tries:

Setting the I²C address:

The same procedure as detailed in the section "Getting Started", see above.

Polling the I²C bus:

The same procedure as detailed in the section "Getting Started", see above.

This polling is not done as part of a change of address. Therefore, the device will give information on the polled devices, and return to the menu immediately afterwards.

Advanced command usage:

Due to the way the Arduino Serial library works, you need not wait for the prompt to enter the next command. It reads command characters and numerical characters separately as well thus:

R11 13 will read thirteen bytes starting at EEPROM address 11.

W25Hey!This is a test@64@ will write the string Hey!This is a test@@ starting at EEPROM address 25.