EEPROM Programming with Raspberry Pi
I needed to program a few bytes in a 24C02 chip and it turned out it was a longer than expected affair. I’m documenting this step by step in case I ever need it again.
1. Preliminaries #
So I started with an oldish Raspberry Pi 3 that was sitting unused in a drawer. I downloaded the Raspberry Pi Imager and created a new image:
It is a good idea to customize the OS to set user account:
and enable SSH access:
Install the micro SD card on the RPI. Use PuTTY as a SSH client to connect to the RPI.
Use the raspi-config
(sudo raspi-config
) tool to enable I2C kernel module:
If you are at it, you can also enable the VNC server to have a GUI interface. Raspbian uses WayVNC server and, by default, it is configured to use encryption. This is not supported by TightVNC (the client that I’m using) and other VNC clients. If you don’t want to install WayVNC client, you can disable encryption by editing the /etc/wayvnc/config
file. Change the enable_auth=true
to false
.
2. Hardware #
You need a GPIO breakout board like this:
Raspberry Pi GPIO pins are not 5V compatible or tolerant so you need a level shifter like this one from Adafruit
I put everything together on a breadboard and it looks like this:
3. Software #
Raspberry Pi comes with I2C drivers installed. The only additional package you need is `libi2c-dev':
> sudo apt install libi2c-dev
Clone the eeprog
repository from https://github.com/neacsum/eeprog and build the executable
eeprog> make
Help info for eeprog
program:
eeprog 0.7.6, a 24Cxx EEPROM reader/writer
Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.
Usage: eeprog [-fqxdh] [-16|-8] [ -r addr[:count] | -w addr ] /dev/i2c-N i2c-address
Address modes:
-8 Use 8bit address mode for 24c0x...24C16 [default]
-16 Use 16bit address mode for 24c32...24C256
Actions:
-r addr[:count] Read [count] (1 if omitted) bytes from [addr]
and print them to the standard output
-w addr Write input (stdin) at address [addr] of the EEPROM
-t n write timeout in ms (default 10)
-h Print this help
Options:
-x Set hex output mode
-d Dummy mode, display what *would* have been done
-f Disable warnings and don't ask confirmation
-q Quiet mode
The following environment variables could be set instead of the command
line arguments:
EEPROG_DEV device name(/dev/i2c-N)
EEPROG_I2C_ADDR i2c-address
Examples
1- read 64 bytes from the EEPROM at address 0x54 on bus 0 starting
at address 123 (decimal)
eeprog /dev/i2c-0 0x54 -r 123:64
2- prints the hex codes of the first 32 bytes read from bus 1
at address 0x22
eeprog /dev/i2c-1 0x51 -x -r 0x22:0x20
3- write the current timestamp at address 0x200 of the EEPROM on
bus 0 at address 0x33
date | eeprog /dev/i2c-0 0x33 -w 0x200