Shop OBEX P1 Docs P2 Docs Learn Events
1-button/1-wire memory: sample code — Parallax Forums

1-button/1-wire memory: sample code

ArchiverArchiver Posts: 46,084
edited 2003-07-08 05:46 in General Discussion
All-
Is anyone out there in StampLand familiar with sample code for reading and
writing
to 1-button IC memory? I'm especially interested in sample code for Add-Only
memory, but anything will surely help.
Thanks,
-Mark

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-07-08 05:46
    On 8 Jul 03 at 2:33, mmarpet wrote:

    > Is anyone out there in StampLand familiar with sample code for
    > reading and writing to 1-button IC memory? I'm especially
    > interested in sample code for Add-Only memory...

    Mark-

    The following BS2p routines for the DS1985 16Kbit add-only EPROM
    iButton ought to get you started.

    Regards,

    Steve


    '{$STAMP BS2p}
    '**************************************************************************
    '
    ' DS1985 16 KBit Add Only iButton
    ' - for simplicity, SKIP ROM used throughout
    '
    '**************************************************************************

    ' Universal 1-Wire ROM commands
    READ_ROM CON $33
    SKIP_ROM CON $CC
    MATCH_ROM CON $55
    SEARCH_ROM CON $F0
    SEARCH_FUNC CON $EC

    ' I/O pin constants
    BUS CON 15 ' 1-Wire bus
    PROG_PULSE CON 14 ' programming pulse (active low--pullup!)

    ' OWIN, OWOUT constants
    RESET_NONE CON 0
    RESET_PRE CON 1
    RESET_POST CON 2
    RESET_BOTH CON 3

    ' conventional variables
    memory_address VAR WORD
    in_byte VAR BYTE(10)
    i VAR BYTE
    j VAR BYTE


    '**************************************************************************
    ' read ROM-based identifier...
    '
    ' 1-Wire transactions summary:
    ' ---> [noparse][[/noparse]reset]
    ' ---> READ ROM
    ' <--- 8 Serial # identifier bytes
    '**************************************************************************

    OWOUT BUS,RESET_PRE,[noparse][[/noparse]READ_ROM] ' send READ ROM
    OWIN BUS,RESET_PRE,[noparse][[/noparse]STR in_byte\8] ' read 8-byte serial identifier
    DEBUG CR,"Serial # "
    FOR i = 7 TO 0 ' display identifier high order
    DEBUG HEX2 in_byte(i) ' byte first
    NEXT


    '**************************************************************************
    ' read and display last four bytes of memory...
    '
    ' 1-Wire transactions summary:
    ' ---> [noparse][[/noparse]reset]
    ' ---> SKIP ROM
    ' ---> READ MEMORY command
    ' ---> 2-byte memory address
    ' <--- 4 data bytes
    ' <--- 2 CRC bytes
    '**************************************************************************
    memory_address = $7FC
    OWOUT
    BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$F0,memory_address.LOWBYTE,memory_address.HIGHBYTE]
    OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\6]
    DEBUG CR,"DS1985 memory: "
    FOR i = 0 TO 3 ' retrieve bytes read
    DEBUG HEX2 in_byte(i)," "
    NEXT


    '**************************************************************************
    ' do extended memory (EPROM) read...
    '
    ' 1-Wire transactions summary:
    ' ---> [noparse][[/noparse]reset]
    ' ---> SKIP ROM
    ' ---> EXTENDED MEMORY READ command
    ' ---> 2-byte memory address
    ' <--- 1 address redirection byte
    ' <--- 2 CRC bytes
    ' <--- 32 data bytes
    ' <--- 2 more CRC bytes
    '**************************************************************************
    memory_address = $7E0
    OWOUT
    BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$A5,memory_address.LOWBYTE,memory_address.HIGHBYTE]
    OWIN BUS,RESET_NONE,[noparse][[/noparse]STR in_byte\3] ' get redirection and CRC bytes
    DEBUG CR,"Redirection byte: ",HEX2 in_byte
    DEBUG CR,"Extended memory data: "
    FOR i = 0 TO 31
    OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
    DEBUG HEX2 in_byte," "
    NEXT
    OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
    OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]



    '**************************************************************************
    ' write $F8 to extended memory (EPROM) location $7FF:
    '
    ' 1-Wire transactions summary:
    ' ---> [noparse][[/noparse]reset]
    ' ---> SKIP ROM
    ' ---> EXTENDED MEMORY WRITE command
    ' ---> 2-byte memory address
    ' ---> 1 data byte = $F8
    ' <--- 2 CRC bytes
    ' <--- 32 data bytes
    ' <--- 2 more CRC bytes
    ' [noparse][[/noparse]12 volt programming pulse]
    ' <--- 1 data byte
    '**************************************************************************
    memory_address = $7FF
    OWOUT
    BUS,RESET_PRE,[noparse][[/noparse]SKIP_ROM,$0F,memory_address.LOWBYTE,memory_address.HIGHBYTE,$F8]
    OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
    OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
    PULSOUT PROG_PULSE,600 ' 480 usec / 0.8
    OWIN BUS,RESET_NONE,[noparse][[/noparse]in_byte]
    DEBUG CR,"Readback of write: ",HEX2 in_byte

    STOP
Sign In or Register to comment.