Shop OBEX P1 Docs P2 Docs Learn Events
Will the Basic Stamp program a EEPROM — Parallax Forums

Will the Basic Stamp program a EEPROM

agent319agent319 Posts: 7
edited 2013-11-07 11:44 in BASIC Stamp
If put an EEPROM on the Basic Stamp breadboard can I access it and reprogram the EEPROM?

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2013-10-30 15:29
    Welcome to the Forum!


    Assuming that your EEPROM is I2C, then yes.... What is the part number of the EEPROM?


    This link may be helpful:

    http://forums.parallax.com/showthread.php/82908-I2C-On-A-BASIC-Stamp
  • agent319agent319 Posts: 7
    edited 2013-10-31 07:08
    The EEPROM # is ST24C08 the datasheet says it's a serial I2C.

    Thank you for your help
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2013-10-31 12:08
    Here is code written by Jon Williams that communicates to a 24LC08 with a Basic Stamp II that should work
    ' =========================================================================
    '
    '   File....... 24LC08.BS2
    '   Purpose.... 24LC08 demo with a BS2/BS2e/BS2sx
    '   Author..... Jon Williams, Parallax
    '   E-mail..... jwilliams@parallax.com
    '   Started....
    '   Updated.... 10 SEP 2004
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    
    ' -----[ Program Description ]---------------------------------------------
    
    
    ' -----[ Revision History ]------------------------------------------------
    
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    SDA             PIN     0                       ' I2C serial data line
    SCL             PIN     1                       ' I2C serial clock line
    
    
    ' -----[ Constants ]-------------------------------------------------------
    
    Ack             CON     0                       ' acknowledge bit
    Nak             CON     1                       ' no ack bit
    
    EE24LC08        CON     %1010 << 4
    
    
    ' -----[ Variables ]-------------------------------------------------------
    
    slvAddr         VAR     Byte                    ' I2C slave address
    devNum          VAR     Nib                     ' device number (0 - 7)
    addrLen         VAR     Nib                     ' bytes in word addr (0 - 2)
    wrdAddr         VAR     Word                    ' word address
    
    i2cData         VAR     Byte                    ' data to/from device
    i2cWork         VAR     Byte                    ' work byte for TX routine
    i2cAck          VAR     Bit                     ' Ack bit from device
    
    test            VAR     Nib
    outVal          VAR     Byte
    inVal           VAR     Byte
    fails           VAR     Word
    
    
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    
    ' -----[ Initialization ]--------------------------------------------------
    
    Check_Module:
      #IF ($STAMP >= BS2P) #THEN
        #ERROR "Use I2COUT and I2CIN!"
      #ENDIF
    
    Setup:
      addrLen = 1                                   ' one word address byte
    
      DEBUG CLS
      DEBUG "24LC08 Demo    ", CR,
            "---------------", CR,
            "Address...     ", CR,
            "Output....     ", CR,
            "Input.....     ", CR,
            "Status....     ", CR,
            "Errors....     "
    
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
      fails = 0
      FOR wrdAddr = 0 TO 1023                       ' test all locations
        slvAddr = EE24LC08 | (wrdAddr.BYTE1 << 1)   ' set block bits
        DEBUG CRSRXY, 11, 2, DEC4 wrdAddr
        FOR test = 0 TO 3                           ' use four patterns
          LOOKUP test, [$FF, $AA, $55, $00], outVal
          DEBUG CRSRXY, 11, 3, IHEX2 outVal
          i2cData = outVal
          GOSUB Write_Byte
          PAUSE 10
          GOSUB Read_Byte
          inVal = i2cData
          DEBUG CRSRXY, 11, 4, IHEX2 inVal,
                CRSRXY, 11, 5
          IF (inVal = outVal) THEN
            DEBUG "Pass "
          ELSE
            fails = fails + 1
            DEBUG "Fail ", CRSRXY, 11, 6, DEC fails
            EXIT                                    ' terminate location
          ENDIF
          PAUSE 10
        NEXT
      NEXT
      IF (fails = 0) THEN
        DEBUG CRSRXY, 11, 6, "None. All locations test good."
      ENDIF
      END
    
    
    ' -----[ Subroutines ]-----------------------------------------------------
    
    
    
    
    ' =====[ High Level I2C Subroutines]=======================================
    
    ' Random location write
    ' -- pass device slave address in "slvAddr"
    ' -- pass bytes in word address (0, 1 or 2) in "addrLen"
    ' -- word address to write passed in "wrdAddr"
    ' -- data byte to be written is passed in "i2cData"
    
    Write_Byte:
      GOSUB I2C_Start                               ' send Start
      i2cWork = slvAddr & %11111110                 ' send slave ID (write)
      GOSUB I2C_TX_Byte
      IF (i2cAck = Nak) THEN Write_Byte             ' wait until not busy
      IF (addrLen > 0) THEN
        IF (addrLen = 2) THEN
          i2cWork = wrdAddr.BYTE1                   ' send word address (1)
          GOSUB I2C_TX_Byte
        ENDIF
        i2cWork = wrdAddr.BYTE0                     ' send word address (0)
        GOSUB I2C_TX_Byte
      ENDIF
      i2cWork = i2cData                             ' send data
      GOSUB I2C_TX_Byte
      GOSUB I2C_Stop
      RETURN
    
    
    ' Random location read
    ' -- pass device slave address in "slvAddr"
    ' -- pass bytes in word address (0, 1 or 2) in "addrLen"
    ' -- word address to write passed in "wrdAddr"
    ' -- data byte read is returned in "i2cData"
    
    Read_Byte:
      GOSUB I2C_Start                               ' send Start
      IF (addrLen > 0) THEN
        i2cWork = slvAddr & %11111110               ' send slave ID (write)
        GOSUB I2C_TX_Byte
        IF (i2cAck = Nak) THEN Read_Byte            ' wait until not busy
        IF (addrLen = 2) THEN
          i2cWork = wrdAddr.BYTE1                   ' send word address (1)
          GOSUB I2C_TX_Byte
        ENDIF
        i2cWork = wrdAddr.BYTE0                     ' send word address (0)
        GOSUB I2C_TX_Byte
        GOSUB I2C_Start
      ENDIF
      i2cWork = slvAddr | %00000001                 ' send slave ID (read)
      GOSUB I2C_TX_Byte
      GOSUB I2C_RX_Byte_Nak
      GOSUB I2C_Stop
      i2cData = i2cWork
      RETURN
    
    
    ' -----[ Low Level I2C Subroutines ]---------------------------------------
    
    ' *** Start Sequence ***
    
    I2C_Start:                                      ' I2C start bit sequence
      INPUT SDA
      INPUT SCL
      LOW SDA
    
    Clock_Hold:
      DO : LOOP UNTIL (SCL = 1)                     ' wait for clock release
      RETURN
    
    
    ' *** Transmit Byte ***
    
    I2C_TX_Byte:
      SHIFTOUT SDA, SCL, MSBFIRST, [i2cWork\8]      ' send byte to device
      SHIFTIN SDA, SCL, MSBPRE, [i2cAck\1]          ' get acknowledge bit
      RETURN
    
    
    ' *** Receive Byte ***
    
    I2C_RX_Byte_Nak:
      i2cAck = Nak                                  ' no Ack = high
      GOTO I2C_RX
    
    I2C_RX_Byte:
      i2cAck = Ack                                  ' Ack = low
    
    I2C_RX:
      SHIFTIN SDA, SCL, MSBPRE, [i2cWork\8]         ' get byte from device
      SHIFTOUT SDA, SCL, LSBFIRST, [i2cAck\1]       ' send ack or nak
      RETURN
    
    
    ' *** Stop Sequence ***
    
    I2C_Stop:                                       ' I2C stop bit sequence
      LOW SDA
      INPUT SCL
      INPUT SDA
      RETURN
    
  • agent319agent319 Posts: 7
    edited 2013-11-07 09:38
    I see in the program the Pin 0 is connected to SDA and Pin 1 is connected to SCL. What other connections will I need?
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2013-11-07 10:10
    Typically with I2C you will have a pull-up resistor on the SDA and SCL lines anywhere from 4.7k to 10k


    Check out this link : (you will want to look for nv115 within the download)

    http://www.parallax.com/downloads/nuts-and-volts-basic-stamps-volume-5
  • agent319agent319 Posts: 7
    edited 2013-11-07 11:44
    That worked!!! All passed
Sign In or Register to comment.