Shop OBEX P1 Docs P2 Docs Learn Events
i2c and 24lc256 reads / writes problem — Parallax Forums

i2c and 24lc256 reads / writes problem

Zap-oZap-o Posts: 452
edited 2011-06-23 09:05 in Propeller 1
what am I doing wrong? Trying to simply read and or write to eeprom using the PASM I2C Driver object in the object exchange.
var

 long MemVarOne 

Pub main
 
  i2c.initialize(scl)
  MemVarOne  := Read_HighMem($8000)
 
Pub Read_HighMem(address)

    return i2c.ReadLong(SCL,eepromAddress, address)

Pub Write_HighMem(address, data)

    i2c.WriteLong(SCL,eepromAddress,address, data)
      

Is it simply because the variable is a long and the object pulls bytes?

Comments

  • JavalinJavalin Posts: 892
    edited 2011-06-23 07:41
    you need an address for the eeprom - as I2C is a bus each device has an address and locations within a device are address'ed too.

    Add something like this:
    CON
      eepromAddress = %1010_0000
    

    and try it.

    James
  • Zap-oZap-o Posts: 452
    edited 2011-06-23 07:50
    Yes sorry my address is

    eepromAddress = $A0

    Still not going well. I must be overlooking something?
  • JavalinJavalin Posts: 892
    edited 2011-06-23 07:59
    can you post your write code? To test the the hardware look at the i2cObject v2.1 in the http://obex.parallax.com which contains a working read/write test.
  • Zap-oZap-o Posts: 452
    edited 2011-06-23 08:08
    Sure the problem I have with that code is that I want to read and write a byte not a byte array. Also want to read write a long again not an array.
      
    var
    
     long MemVarOne 
     Byte MemVarTwo
     byte buffer[32]
        
    Pub main
    
      ser.start(31,30,0,19200)
      i2c.initialize(scl)
      MemVarTwo~
      
     
        
      MemVarTwo := 66  
      writeIt   
      readIt  
    
      ser.str(string("[read ")) 
      ser.dec(buffer[5])
      ser.tx("]")
      
    Pri ms(Delay)
             
      Waitcnt((clkfreq / 1_000) * Delay + cnt)
      
    PRI readIt
    
      if i2c.ReadPage(28, EEPROM, eepromAddress, @MemVarTwo, 1)
        abort 
    
    PRI writeIt | startTime
    
      if i2c.WritePage(28, EEPROM, eepromAddress, @MemVarTwo, 1)
         abort 
      startTime := cnt 
      repeat while i2c.WriteWait(28, EEPROM, eepromAddress)
         if cnt - startTime > clkfreq / 10
           abort
    
    
  • Zap-oZap-o Posts: 452
    edited 2011-06-23 08:10
    Opps

    I solved it.
    ser.str(string("[read ")) 
    ser.dec(MemVarTwo)
    ser.tx("]")
    
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-06-23 08:32
    A 24lc256 is a 256Kbit device, which is 32Kbytes. You can only use addresses from 0 to $7fff. I believe an address of $8000 will wrap around back to 0.
  • Zap-oZap-o Posts: 452
    edited 2011-06-23 09:05
    Wow I see $7FFF is true. Thank you sir. Ill set my max address to $7FFF
Sign In or Register to comment.