The infamous cheap AT24C256 I2C EEPROM breakout board provides 32K bytes of storage for your projects.

  • Cost: ~$2
  • Size: 32768 bytes
  • VCC: 2.7 - 5.5V
  • It includes I2C pull-ups
  • Speeds: 1 MHz (5V), 400 kHz (2.7V, 2.5V)
  • 64-byte Page Write Mode (Partial Page Writes Allowed).
  • I2C address ranges from 0x50 to 0x57 and can be configured using the A jumpers (A0-A2)

🛒

Get Bus Pirate & Accessories

Connections

Bus PirateAT24C256 boardDescription
SDASDAI2C Data
SCLSCLI2C Clock
Vout/VrefVCC5volt power supply
GNDGNDGround

See it in action

Setup

Considering:

  • AT24C256’s datasheet max speed
  • AT24C256 board pull-ups are 10k
  • You’ve purchased a low-quality clone from AliExpress or any other source
  • The length of the Bus pirate cable

We’re going to be very conservative and operate at:

  • 5V, 100kHz.
  • Max current: 50ma.
Bus Pirate [/dev/ttyS0]
HiZ> m i2c

Mode: I2C
I2C speed
 1kHz to 1000kHz
 x. Exit
kHz (400kHz*) > 100
Clock stretching
 1. OFF*
 2. ON
 x. Exit
OFF (1) > 1
I2C> 
  • Use the m mode command and select I2C
  • Configure I2C for 100kHz and 8bits of data

Power supply

Bus Pirate [/dev/ttyS0]
I2C> W 5 50
5.00V requested, closest value: 5.00V
50.0mA requested, closest value: 50.0mA

Power supply:Enabled
Vreg output: 4.9V, Vref/Vout pin: 4.9V, Current: 10.9mA

I2C> 
  • Enable the onboard power supply with the W command, and configure it for 5volts output.
  • Select a current limit of at least 50mA.

Pull-up resistors

Bus Pirate [/dev/ttyS0]
I2C> P
Pull-up resistors: Enabled (10K ohms @ 4.9V)

I2C> 

I2C is an open collector output bus, the Bus Pirate and the at24c256 can only pull the line low to 0 (ground). A pull-up resistor is needed to pull the line high to 1 (5 volts). The Bus Pirate has built-in pull-up resistors that can be enabled with the P command.

I2C address scan

Bus Pirate [/dev/ttyS0]
I2C> scan
I2C address search:
0x50 (0xA0 W) (0xA1 R)
0x58 (0xB0 W) (0xB1 R)

Found 4 addresses, 2 W/R pairs.

I2C> 

Let’s see if we can find the card I2C address. We could look in the datasheet, or we can be lazy and run an I2C address scan.

  • scan - Scan the I2C bus for devices

Write three bytes

Bus Pirate [/dev/ttyS0]
I2C> [0xa0 0x00 0x69 0x41 0x42 0x43]

I2C START
TX: 0xA0 ACK 0x00 ACK 0x69 ACK 0x41 ACK 0x42 ACK 0x43 ACK 
I2C STOP
I2C> 

We’ll write three bytes - ‘A’(0x41), ‘B’(0x42), ‘C’(0x43) - to the EEPROM at memory location 0x69, 0x6A, and 0x6B. The AT24C256 supports partial page writes, so we can write to the EEPROM without needing to write a full 64-byte page.

  • [ - Begin with an I2C START
  • 0xA0 - is the I2C device write address: 0xA0 (the AT24C256 has a 7-bit address, so the Bus Pirate uses the 8-bit address 0xA0 for writing).
  • 0x00 0x69 - is the memory address where we intend to write: 0x69. The AT24C256 has a 16bit/2byte address range.
  • 0x41 0x42 0x43 - are the three data bytes we want to write.
  • ] - End with an I2C STOP

Read three bytes

Bus Pirate [/dev/ttyS0]
I2C> [0xa0 0x00 0x69]

I2C START
TX: 0xA0 ACK 0x00 ACK 0x69 ACK 
I2C STOP
I2C> 

We’ll read three bytes from the EEPROM at memory location 0x69, 0x6A, and 0x6B. To achieve this, two commands are necessary. First, use a write command with no data to indicate the memory address we want to read.

  • [ - Begin with an I2C START
  • 0xA0 - is the I2C device write address: 0xA0 (the AT24C256 has a 7-bit address, so the Bus Pirate uses the 8-bit address 0xA0 for writing).
  • 0x00 0x69 - is the 16bit/2byte memory address to read: 0x69.
  • ] - End with an I2C STOP
Bus Pirate [/dev/ttyS0]
I2C> [0xa1 r:3]

I2C START
TX: 0xA1 ACK 
RX: 0x41 ACK 0x42 ACK 0x43 NACK 
I2C STOP
I2C> 

Second, use the I2C read address to read the bytes from that memory location.

  • [ - Begin with an I2C START
  • 0xA1 - is the I2C device read address to access data at the location we set with the previous command: 0xA1 (the AT24C256 has a 7-bit address, so the Bus Pirate uses the 8-bit address 0xA1 for reading).
  • r:3 - reads back three bytes of data. Bytes read: 0x41 0x42 0x43 (‘A’, ‘B’, ‘C’). Each byte is separated by a space and is located at the memory addresses 0x69, 0x6A, and 0x6B respectively.
  • ] - End with an I2C STOP

Get a Bus Pirate

🛒

Get Bus Pirate & Accessories

Community