Parts: 1K 1-Wire EEPROM (DS2431)
posted Dec 24th 2008 6:00am by Ian Lesnetfiled under: parts, tool hacks

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.0×2D 0×54 0xD2 0xEF 0×00 0×00 0×00 0×2B <–address
*DS2431 1K EEPROM <– type
2.0×2D 0xFE 0×8D 0×43 0×01 0×00 0×00 0×52
*DS2431 1K EEPROM
3.0×2D 0×2B 0xED 0xEF 0×00 0×00 0×00 0×7C
*DS2431 1K EEPROM
Found 0×03 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 0×0f 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) 0×0f 0×00 0×00 0 1 2 3 4 5 6 7 <–command
1WIRE BUS RESET OK
1WIRE WRITE ROM COMMAND: MATCH (0×55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0×2D 0×54 0xD2 0xEF 0×00 0×00 0×00 0×2B
1WIRE WRITE: 0×0F <–write to scratch pad
1WIRE WRITE: 0×00 <–begin address byte 1
1WIRE WRITE: 0×00 <–begin address byte 2
1WIRE WRITE: 0×00 <–data
1WIRE WRITE: 0×01
1WIRE WRITE: 0×02
1WIRE WRITE: 0×03
1WIRE WRITE: 0×04
1WIRE WRITE: 0×05
1WIRE WRITE: 0×06
1WIRE WRITE: 0×07
1-WIRE>
The MATCH ROM macro, (85), isolates the the first device, (1). 0×0f 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 (0×55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0×2D 0×54 0xD2 0xEF 0×00 0×00 0×00 0×2B
1WIRE WRITE: 0xAA <–read scratch pad
1WIRE BULK READ, 0×03 BYTES: <–access code
0×00 0×00 0×07
1WIRE BULK READ, 0×08 BYTES:<–verify our data
0×00 0×01 0×02 0×03 0×04 0×05 0×06 0×07
1WIRE BULK READ, 0×02 BYTES:<–inverse CRC
0×44 0×67
1WIRE BULK READ, 0×02 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 (0×00 0×00 0×07), followed by the data contained in the scratch pad.
1-WIRE>(85)(1) 0×55 0×00 0×00 0×07
1WIRE BUS RESET OK
1WIRE WRITE ROM COMMAND: MATCH (0×55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0×2D 0×54 0xD2 0xEF 0×00 0×00 0×00 0×2B
1WIRE WRITE: 0×55 <–copy to EEPROM command
1WIRE WRITE: 0×00<–access code (3 bytes)
1WIRE WRITE: 0×00
1WIRE WRITE: 0×07
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 0×55 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 0×00 0×00 r:8 r:8
1WIRE BUS RESET OK
1WIRE WRITE ROM COMMAND: MATCH (0×55) *follow with 64bit address
1WIRE ADDRESS MACRO 1: 0×2D 0×54 0xD2 0xEF 0×00 0×00 0×00 0×2B
1WIRE WRITE: 0xF0 <–read memory
1WIRE WRITE: 0×00 <–start address (2 bytes)
1WIRE WRITE: 0×00
1WIRE BULK READ, 0×08 BYTES: <–read back data
0×00 0×01 0×02 0×03 0×04 0×05 0×06 0×07
1WIRE BULK READ, 0×08 BYTES: <–read beyond our data
0×00 0×00 0×00 0×00 0×00 0×00 0×00 0×00
1-WIRE>
Command 0xf0 followed by a two byte memory address (0×00 0×00) 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.

Maxim has a super nice java base program to test directly your on wire device via the web. You need to have the serial to iWire converter. It is a integreted chip.
http://www.maxim-ic.com/products/ibutton/software/1wire/OneWireViewer.cfm
click the “Launch the oneWireViewer”
I have tested a iButton with some temperature and a switch. REally neat.
Posted at 8:30 am on Dec 24th, 2008 by Jerome