Image may be NSFW.
Clik here to view.
The Maxim DS2431 1K EEPROM is 1-Wire device that adds storage to a project using a single microcontroller pin. We previously interfaced a 1-wire thermometer, but this EEPROM is slightly different because it draws power directly from the 1-Wire bus. Grab the datasheet (PDF) and follow along while we read and write this simple 1-Wire memory.
DS2431 1-Wire 1K EEPROM (Digikey #DS2431+-ND, $1.67)
We used our Bus Pirate universal serial interface to demonstrate the DS2431 EEPROM, we covered the proper connections and configuration options in our previous 1-wire post. The DS2431 requires just two connections: ground (pin 1) and 1-Wire/power (pin 2). Pin 3 remains unconnected. Like last time, we used a 2K pull-up resistor with the 1-Wire bus.
First, we use the Bus Pirate’s SEARCH ROM command to identify connected 1-Wire devices.
1-WIRE>(240) <–SEARCH ROM command macro
1WIRE ROM COMMAND: SEARCH (0xF0)
Found devices at:
Macro 1-WIRE address
1.0x2D 0x54 0xD2 0xEF 0x00 0x00 0x00 0x2B <–address
*DS2431 1K EEPROM <– type
2.0x2D 0xFE 0x8D 0x43 0x01 0x00 0x00 0x52
*DS2431 1K EEPROM
3.0x2D 0x2B 0xED 0xEF 0x00 0x00 0x00 0x7C
*DS2431 1K EEPROM
Found 0x03 devices.
The first 10 device IDs are available by MACRO, see (0).
1-WIRE>
The SEARCH ROM command reveals that there are 3 EEPROMs connected to the 1-Wire bus. The Bus Pirate stores the 64bit 1-wire addresses in macros so we don’t have to type it every time. We’ll work with the first device, identified by macro (1).
Writing to the DS2431 takes three steps:
- Write data to DS2431’s 8byte ‘scratch pad’ EEPROM buffer
- Verify the scratch pad contents and get the write access key
- Copy data from the scratch pad to the EEPROM for permanent storage.
Command 0x0f writes to the scratch pad. The scratch pad is an 8byte buffer that holds data prior to saving it permanently in the EEPROM.
1-WIRE>(85)(1) 0x0f 0x00 0x00 0 1 2 3 4 5 6 7 <–command
1WIRE BUS RESET OK
1WIRE WRITE ROM COMMAND: MATCH (0x55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0x2D 0x54 0xD2 0xEF 0x00 0x00 0x00 0x2B
1WIRE WRITE: 0x0F <–write to scratch pad
1WIRE WRITE: 0x00 <–begin address byte 1
1WIRE WRITE: 0x00 <–begin address byte 2
1WIRE WRITE: 0x00 <–data
1WIRE WRITE: 0x01
1WIRE WRITE: 0x02
1WIRE WRITE: 0x03
1WIRE WRITE: 0x04
1WIRE WRITE: 0x05
1WIRE WRITE: 0x06
1WIRE WRITE: 0x07
1-WIRE>
The MATCH ROM macro, (85), isolates the the first device, (1). 0x0f is the command to write to the scratch pad, followed by the start address, 0 0. Finally, we send eight bytes of data to save in the scratch pad. The scratch pad is eight bytes long, and all eight bytes will be copied from the scratch pad to the EEPROM at once.
1-WIRE>(85)(1) 0xaa r:3 r:8 r:2 r:2 <–command
1WIRE BUS RESET OK
1WIRE WRITE ROM COMMAND: MATCH (0x55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0x2D 0x54 0xD2 0xEF 0x00 0x00 0x00 0x2B
1WIRE WRITE: 0xAA <–read scratch pad
1WIRE BULK READ, 0x03 BYTES: <–access code
0x00 0x00 0x07
1WIRE BULK READ, 0x08 BYTES:<–verify our data
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07
1WIRE BULK READ, 0x02 BYTES:<–inverse CRC
0x44 0x67
1WIRE BULK READ, 0x02 BYTES:<–all 1s from here
0xFF 0xFF
1-WIRE>
To copy data from the scratch pad to the EEPROM, we must first retrieve a three byte access code from the scratch pad with the command 0xaa. The first three bytes are the access code (0x00 0x00 0x07), followed by the data contained in the scratch pad.
1-WIRE>(85)(1) 0x55 0x00 0x00 0x07
1WIRE BUS RESET OK
1WIRE WRITE ROM COMMAND: MATCH (0x55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0x2D 0x54 0xD2 0xEF 0x00 0x00 0x00 0x2B
1WIRE WRITE: 0x55 <–copy to EEPROM command
1WIRE WRITE: 0x00<–access code (3 bytes)
1WIRE WRITE: 0x00
1WIRE WRITE: 0x07
1-WIRE>!!!! <–read bits
1WIRE READ BIT: 0
1WIRE READ BIT: 1 <–bits alternate, done
1WIRE READ BIT: 0
1WIRE READ BIT: 1
1-WIRE>
Command 0x55 with the correct access code will copy the scratch pad to the data EEPROM. Bit reads (!!!!) alternate between 0 and 1 when the copy completes.
1-WIRE>(85)(1) 0xf0 0x00 0x00 r:8 r:8
1WIRE BUS RESET OK
1WIRE WRITE ROM COMMAND: MATCH (0x55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0x2D 0x54 0xD2 0xEF 0x00 0x00 0x00 0x2B
1WIRE WRITE: 0xF0 <–read memory
1WIRE WRITE: 0x00 <–start address (2 bytes)
1WIRE WRITE: 0x00
1WIRE BULK READ, 0x08 BYTES: <–read back data
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07
1WIRE BULK READ, 0x08 BYTES: <–read beyond our data
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
1-WIRE>
Command 0xf0 followed by a two byte memory address (0x00 0x00) begins the data read process. The first eight bytes (r:8) are the values we wrote earlier. Reads don’t involve the scratch pad and don’t have an 8byte limit, so further reads continue to the end of the memory.
Don’t forget to catch up on any parts posts you may have missed.
Posted in parts, tool hacks Image may be NSFW.
Clik here to view.
Clik here to view.
