Bus Pirate Edu Kit Exercise no.9

From DP

Revision as of 14:12, 25 April 2013 by Arakis (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation , search



BP EK E9 overview.jpg

In this exercise we'll demonstrate how to interface the Bus Pirate with the 25LC040A 512 byte EEPROM IC over the SPI protocol. We'll show you how to write and read date from the EEPROM using the Bus Pirate.

This EEPROM is organized in 32 pages each 16 bytes long, meaning that at any single time only 16 bytes can be read or written to the IC.

The protocol used to communicate with the IC is the standard SPI protocol at a maximum of 10MHz clock speed.

BP EK E9 Instruction.jpg

The internal communication protocol is defined in the datasheet. The first byte sent to the device is the command byte and it defines further communication. There are 6 commands pictured above, which are divided in 3 groups.

BP EK E9 ReadWrite.jpg

The first group is used to read and write data to the EEPROM. When sending or receiving data from the IC the Bus Pirate needs to send the command byte followed by the address of where the data should be written or read to. The subsequent bytes are the data that is either written to or read from the EEPROM.


The second group of commands are the write enable and disable. This is a singly byte command. You simply send 0x06 to enable writing to the EEPROM, or 0x04 to disable it.

BP EK E9 StatusReg.jpg

The third group is intended for reading and writing to the status register. To read the status register you send the appropriate command and the following revived byte is the contents of the status register. To write to it, you send the appropriate command followed by the value of the status register you'd like to set.

The Circuit

BP EK E9 schematic.jpgBP EK E9 circuit.jpg

Breadboard legend

IC Location Breadboard wiring legend
IC PIN1 (+) PIN2 (-)
25LC040A E14 E15
Signal name Contact1 Contact2
5V BP_5V BB_+_left
5V BB_+_left BB_+_right
5V BB_+_left A16
5V BB_+_right J14
5V BB_+_right J15
GND BP_GND BB_-_left
GND BB_-_left A17
  • The (+) and (-) next to PIN1 and PIN2 are intended for devices such as LEDs, where PIN1 should be the anode and connected to a higher potential then PIN2.

Bus Pirate Terminal

HiZ>m<<<the mode command
1. HiZ
2. 1-WIRE
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)

(1)>5<<<select the SPI mode<<<
Set speed:
1. 30KHz
2. 125KHz
3. 250KHz
4. 1MHz

(1)>4<<<set the SPI speed to 1 MHz<<<
Clock polarity:
1. Idle low *default
2. Idle high

(1)>1<<<set clock polarity to idle low
Output clock edge:
1. Idle to active
2. Active to idle *default

(2)>2<<<set output clock edge to active to idle
Input sample phase:
1. Middle *default
2. End

(1)>1<<<select the middle input sample phase
1. CS
2. /CS *default

(2)>2<<<select the inverted CS signal (active low)
Select output type:
1. Open drain (H=Hi-Z, L=GND)
2. Normal (H=3.3V, L=GND)

(1)>2<<<set the output type to normal
SPI>W<<<turn on the power supplies

First we need to setup the SPI protocol as per 25LC040A's datasheet. Once the protocol is setup we turn on the power supplies via the 'W' command.

WRITE: 0x06

Next we send the 'write enable' (0x06) command, which allows us to write data to the EEPROM.

SPI>[0x02 0 1 2 3 4 5]
WRITE: 0x02
WRITE: 0x00
WRITE: 0x01
WRITE: 0x02
WRITE: 0x03
WRITE: 0x04
WRITE: 0x05

Next we'll write 5 bytes to the EEPROM starting at the 0x00 address. To do this we first need to send the 'write data' command (0x02), followed by the address (0x00) where we want to write the data. This is followed by the five bytes we want to write into the EEPROM (0x01, 0x02, 0x03, 0x04, and 0x05).

SPI>[0b11 0 r:5]
WRITE: 0x03
WRITE: 0x00
READ: 0x01 0x02 0x03 0x04 0x05

To check if our data was successfully written we'll read the 5 bytes we just sent to the EEPROM. First sent byte is the 'read data' command, next the starting address of the data we want to read (0x00).

The subsequent 5 bytes are the data located in the memory addresses 0x00 - 0x04, and they correspond to the data we have previously written.

1. HiZ
2. 1-WIRE
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)


Not Working?

Taking it further