Parts: 1K 1-Wire EEPROM (DS2431)

1keeprom-450

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.

26 thoughts on “Parts: 1K 1-Wire EEPROM (DS2431)

  1. hehe..now all they need to do is make a 1 wire PIC :-) with integrated RGB LEDs on the unused GPIO lines.

    Call it the SmartLED, and use it for large area addressable displays. Bonus if you can program it using IR light while holding its Vcc at +11V (which the internal regulator steps down to +5V Vcc)

  2. @gcl
    Half the reason HAD published this article is to publicize the bus pirate.
    putting that aside, the bus pirate is designed to be capable of doing many types of serial formants. 1, 2, and 3 wire, as well as rs-232, and possibly some others with firmware updates.
    Now, when I buy that nifty I2C widget, I don’t have to spend an hour or two programming a uC, I can just hook it up and manipulate the raw data directly from a terminal.

  3. So I’ve got the data off my DS2431 (SN). Is there a way to just copy the data from one to another? I want to duplicate the card I already have. Do I just rewrite the memory from the one I have to the empty one?

  4. Is there any chance to copy from one ds2431 to another, actually to clone them??? also is this possible with bus pirate??? or is it possible to resset ds2431 with buspirate??? thanx in advance :)

  5. One question, how to write second 8bytes, after sucessfully written first 8bytes in above example…how write to scratch pad and copy to eeprom commands should look like??? ofcourse with bus pirate interface… :)

  6. hiya gents
    read this post with interest, has any work been done with the ds2502u
    i have a ibutton which i need to replicate purely for lab purposes,does not have to be replicated in ibutton format
    be very grateful as to know if i am chasing a dead duck or not

    cheers
    keith

  7. Hello guys.
    I want to read data from one DS2431 and write it to another one. I have read this post but i can’t understand how i should connect the 1-Wire usb adaptor (and wich pin of it)to the circuit, what is the materials of the circuit, how they are connected between them and more or less how do i make happend and work this nice idea..
    Exist somewhere these information for download them?
    Regards friends

    1. The only way you can do that is by connecting the both to your adapter, DQ leads go to the hot lead and GND to the ground one. The sheet for the adapter will say which ones they are. Software on the host should enable you to copy the contents from one to the other.

      To explain completely is not possible here.

  8. Is it possible to read The data in DS2431 and then write to another chip Ds2431 using this bus pirate.apart from bus pirate is there need for any other?

    1. Everything is fine until I reset the bus. Then the data is all 0xFF again. Or if I do a couple of consecutive reads, the data reverts back to 0xFF starting from the LSB. This is an unidentified / unlisted (2D 1002, a Russian site states it’s a DS2340(A?)) chip, yet works with commands state above.

      1. Actually, I can only write and then verify what I write if I do a (85)(1) 0x0f 0x00 0x01 0 1 2 3 4 5 6 7
        But when I try to copy data from scratch to EEPROM like this (85)(1) 0x55 0x00 0x01 0x07
        No alternating bits, nothing is written either…

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.