Shop OBEX P1 Docs P2 Docs Learn Events
I2C Addressing problems — Parallax Forums

I2C Addressing problems

Chicago MikeChicago Mike Posts: 88
edited 2007-05-15 19:43 in Propeller 1
I'm having a bit of a problem with my interfacing to an I2C EEPROM (Regardless of model, tried the common 24LC256 and 24LC512), all the results are similar.·Below I have the two modules that are reading and Write respectively, with a bit of trimming. Basicly, the ReadEEPROM will take a LONG value between 1-500, convert it to a bit address and attempt to read that byte, afterreading, it is taking that value (which would be 0-6) and displaying the character listed in the lookupz table.

The write does the same thing, taking an address, and writing at this point a 1 or 2 to the corresponding address. (I haven't made the other cases yet because of the problem that follows). So anyway, easy right? Heres my problem, The read seems to work properly, however the the write is happening one BYTE too high. Hence the result of address 5 is showing up in address 6??

I've commented out my attempt with the "i2cobject" and also tried Mike Greens "Basic_I2C_Driver", with the same results. So I know its sometime I'm doing. My Address math seems right? Any help would be great! Thanks!


PUB ReadEEPROM(Address) | Status, PrintMe
··· Address:=(Address*8)-8
'··· Status := fram.readLocation(Page1, Address, 16, 8)
··· Status:=tester.ReadByte(14, $A0, Address)
··· LCD.MOVE(16,2)
··· PrintMe:= lookupz(Status: String("-"),String("+"),String("1"),String("2"),String("3"),String("4"),String("5"))
··· LCD.str(PrintMe)

Pub WriteEEPROM(Address)
····· Address:=(Address*8)-8
····· case check_buttons
······· iBtnGood:
'········ fram.writeLocation(Page1, Address, 1, 16, 8)
········· tester.WriteByte(14, $A0, Address, 1)·
······· iBtnBad:
'········· fram.writeLocation(Page1, Address, 2, 16, 8)
········· tester.WriteByte(14, $A0, Address, 2)
····· WAITCNT(5_000_000 + CNT)
··

Post Edited (Chicago Mike) : 5/15/2007 5:41:17 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-15 17:42
    There doesn't seem to be anything wrong with the code you've shown (other than that you're writing a 4 or 5, not a 1 or 2). I can't see any way for the write to behave as you describe. You must be calling WriteEEPROM with an incorrect address somehow.
  • Chicago MikeChicago Mike Posts: 88
    edited 2007-05-15 18:26
    Yeah, I typed in the write values wrong, but as you said, that still doesn't explain the behavior. I'll dig again this afternoon. Address is being passed as a LONG type, which I can't see as being a problem in this case, as its working, just the one address placement off. IF I'm doing a READEEPROM, then a WRITE EEPROM, the FULL address is being re-referenced on the Write again (or at least from what I can figure in the Object), so the read isn't offseting my read pointer like a sequencial read would?
  • Chicago MikeChicago Mike Posts: 88
    edited 2007-05-15 18:49
    OK.... I found it. It was basic. I was running the EEPROM read after another cog was incrementing the variable via an encoder. Stupid mistake. Thanks though!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-15 19:43
    Ah yes, the bane of multiprocessing ... shared variables (whether you think they're shared or not). Glad you found it.
Sign In or Register to comment.