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.

Comments

  1. Jerome says:

    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.

  2. Maj says:

    Excuse me for not being an electrician but wouldn’t one wire for ground and one for power make it two wire?

  3. Curtisbeef says:

    There are 3 wires in fact… But only 1 is used for Data. The other 2 being Vcc and Gnd. But it only uses 1 Wire for data so they call them 1 Wire…

  4. andre says:

    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)

  5. GCL says:

    HAH!
    Try using them under Linux, and an actual One-Wire adapter. http://www.owfs.org does that and more. I should know I happen to be a member.

  6. gcl says:

    Hello!
    Uh, I see I am still there, but here goes:
    Why is the bus pirate used? Maxim makes excellent devices to access the bus, and naturally software is available. GPL covered for the http://www.owfs.org and of course Maxim publishes their own entries.

  7. KillerSpud says:

    @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.

  8. James says:

    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?

  9. Peter says:

    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 :)

  10. Peter says:

    Ok, thanx for quick reply :) At least data can be copied, so we will see what happens… :)

  11. Peter says:

    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… :)

  12. keith says:

    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

  13. LaVa says:

    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

  14. Sadhana Santhosh says:

    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?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 96,380 other followers