Writing to 1-wire EEPROM


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77

    Unhappy Writing to 1-wire EEPROM

    I need to write to and then read back from a 1-wire EEPROM.
    I have an iButton DS1973 which has the same insides as a
    standard 1-wire DS2433 4Kb EEPROM.

    I have read the datasheet, tried without success, searched the PBP and other sites but no answer.
    I just need an example on how to write 1 byte to an address on the EEPROM and then read it back again. This code I tried but doesn't work:

    ADCON1=7 ' Set all Ports to Digital I/O
    OPTION_REG.7=0 ' Enable weak PullUps
    TRISB.0=0

    MEM VAR BYTE
    RESULT VAR BYTE[4]

    iButton var PortD.2


    START:

    SEROUT2 PORTB.0,16416,["START",10,13] 'just to test the comms

    'WRITE TO EEPROM

    OWOUT ibutton,1,[$CC,$0F,$00]
    OWOUT IBUTTON,1,[$54,$65,$73,$74] 'write characters "test"
    OWOUT IBUTTON,1,[$CC,$FF,$A5]
    PAUSE 25

    'READ FROM EEPROM

    OWOUT ibutton,0,[$CC,$F0,$00]
    FOR MEM=1 TO 32
    OWIN IBUTTON,0,[RESULT]
    SEROUT2 PORTB.0,16416,[RESULT]
    PAUSE 100
    NEXT MEM

    END

    Can anyone tell me what I have done wrong?

    Regards

    Chris

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77


    Did you find this post helpful? Yes | No

    Red face CRC for iButton EEPROM

    I am only going to load data on the iButton EEPROM once, is it nessesary to use the "Cyclic Redundancy Checks" to write to the device or is it just an option like parity is on other serial systems. Can I not just write directly to it without vast CRC calculations and then read it out to check? I only am going to need about 12 bytes to be written in total for button identification. (I am using the code on the button to change a pic's options, plug button 1 in it does one thing, plug button 2 in it does another)

    It must be simpler?

    Regards

    Chris

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The Write Scratchpad command requires a 2-byte address. You're only giving it 1.
    OWOUT ibutton,1,[$CC,$0F,$00,$00]

    After that command, you can't "RESET" before the data
    OWOUT IBUTTON,0,[$54,$65,$73,$74] 'write characters "test"

    Not sure what this was supposed to be. There isn't a $FF command. Due to the delay afterwards, it looks like that was supposed to do the Write.
    OWOUT IBUTTON,1,[$CC,$FF,$A5]
    PAUSE 25


    But instead, you need to READ the scratchpad memory to get the correct authorization code, so that you can do a "Copy Scratchpad" that actually writes it to EEPROM.

    After that, you can do the "Read Memory" command. (With 2-byte address again)

    Look at the COPY SCRATCHPAD [55h] section in the datasheet.

    hth,
    DT

  5. #5
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77


    Did you find this post helpful? Yes | No

    Talking iButton

    Thanks Darrel,

    Does this mean that I don't have to use the CRC calculation system?

    Regards

    Chris

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by crhomberg View Post
    Does this mean that I don't have to use the CRC calculation system?
    Unless you want a program that's not susceptible to spurious noise Errors, NO, you don't have to use CRC's.
    DT

  7. #7
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77


    Did you find this post helpful? Yes | No

    Red face EEPROM still not working

    Hi,

    I modified my program using the authorisation code but I still seem not to get my data back.
    This is my latest version (for a 16F877A)

    '************************************************* ***************
    '* Name : eeprom.BAS *
    '* ************************************************** ************
    @ device hs_OSC, wdt_on, pwrt_on, protect_off
    DEFINE OSC 20

    ADCON1=7 ' Set all Ports to Digital I/O
    OPTION_REG.7=0 ' Enable weak PullUps


    TRISC.0=1
    TRISC.1=1
    TRISC.2=1
    TRISB.0=0

    iButton var PortD.2

    MEM VAR BYTE
    RESULT VAR BYTE[4]
    Taddr var byte[2] 'target address 2 bytes
    ES var byte 'ending offset data status

    START:
    SEROUT2 PORTB.0,16416,["START",10,13]

    'WRITE TO EEPROM
    OWOUT ibutton,1,[$CC,$0F,$00,$00] 'Write to scratchpad
    OWOUT IBUTTON,0,[$54,$65,$73,$74] 'Write characters "test"
    OWout IBUTTON,0,[$CC,$AA]
    owin ibutton,0,[Taddr[0],Taddr[1],ES] 'read back the scratchpad to get the Authorisation code
    owout ibutton,0,[$CC,$55] 'Write back the contents of the target address & E/S register
    owin ibutton,0,[Taddr[0],Taddr[1],ES] 'to allow copy scratchpad to take place.

    PAUSE 25

    'READ FROM EEPROM
    OWOUT ibutton,0,[$CC,$F0,$00,$00]
    FOR MEM=1 TO 32
    OWIN IBUTTON,0,[RESULT]
    SEROUT2 PORTB.0,16416,[RESULT]
    PAUSE 100
    NEXT MEM

    END

    Where have I gone wrong?

    Regards

    Chris

  8. #8
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77


    Did you find this post helpful? Yes | No

    Talking At Last Working

    Thanks Darrel,

    I got it right, it is now send back the letters test with this code...

    'WRITE TO EEPROM
    OWOUT ibutton,1,[$CC,$0F,$00,$00] 'Write to scratchpad
    OWOUT IBUTTON,0,[$54,$65,$73,$74] 'Write characters "test"
    OWout IBUTTON,1,[$CC,$AA] 'get ready to read scratchpad
    owin ibutton,0,[Taddr[0],Taddr[1],ES] 'read back the scratchpad to get the Authorisation code
    owout ibutton,1,[$CC,$55] 'Write back the contents of the target address & E/S register
    owout ibutton,0,[Taddr[0],Taddr[1],ES] 'to allow copy scratchpad to take place.

    PAUSE 25

    'READ FROM EEPROM
    OWOUT ibutton,1,[$CC,$F0,$00,$00]
    FOR MEM=1 TO 4
    OWIN IBUTTON,0,[RESULT]
    SEROUT2 PORTB.0,16416,[RESULT]
    PAUSE 100
    NEXT MEM

    END

    Thanks Chris

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Thumbs up

    WooHoo! There ya go.
    That looks much better.

    Tricky little 1's and 0's in the mode.

    Nice work!
    <br>
    DT

  10. #10
    Join Date
    Apr 2007
    Location
    Santiago, Chile
    Posts
    77


    Did you find this post helpful? Yes | No

    Talking That's it Babe

    I am so proud of the code I wrote for the DS1994 REAL TIME CLOCK & DS1973 EEPROM I think I must post both as they work so well and finally are relatively simple and there seems to be no sample code on the net.
    Where on the site is the place for Code Samples?

    Regards

    Chris

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Careful, that feeling of "Elation" is addictive.

    Code examples always welcome.
    http://www.picbasic.co.uk/forum/forumdisplay.php?f=11
    DT

Similar Threads

  1. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 07:31
  2. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 13:35
  3. 32 bit square root
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 6th May 2009, 03:37
  4. one line led light make image
    By bioul in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 12:19
  5. HSERIN doesn´t work
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2007, 14:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts