Shop OBEX P1 Docs P2 Docs Learn Events
EEprom Nighmare — Parallax Forums

EEprom Nighmare

crgwbrcrgwbr Posts: 614
edited 2007-03-28 23:52 in Propeller 1
I'm currently writting a program that needs to store 6 values in an EEprom with it's SCL pin attached to Pin 0, SDA to 1.· A0, A1, and A2 are conected to ground.· I am using Mike Green's Minimal I2C routines.· The problem is when I try to retreve the values.· For example, on one occasion I set the following Values to be written:
FutureD1 := 1
FutureD2 := 108
FutureD1 := 200
FutureD2 := 100 

FutureD1 := 150
FutureD2 := 50

··However, when I retreved the Values, instead of being 1, 108, 200, 100, 150, 50; they were 1, 255, 0, 255, 255, 255.· I've been working on this problem for days,·it still·makes no sense to me.· Hopefully it will to you.· I've posted an excerpt of the code below.
Thanks,
Craig
PUB Load
Serial.Start(rx, tx, %0000, 9600)
Serial.SetDelimiter("k")
eeprom.i2cReadPage(0, $A0, %0000111111110100000, @Depth1, 1)
eeprom.i2cReadPage(0, $A0, %0000111111110110000, @Depth2, 1)
eeprom.i2cReadPage(0, $A0, %0000111111111000000, @Depth3, 1)
eeprom.i2cReadPage(0, $A0, %0000111111111010000, @Depth4, 1)
eeprom.i2cReadPage(0, $A0, %0000111111111100000, @Depth5, 1)
eeprom.i2cReadPage(0, $A0, %0000111111111110000, @Depth6, 1)
waitcnt(1_000_000 + cnt)
Serial.DEC(Depth1)
Serial.tx(13)
Serial.DEC(Depth2)
Serial.tx(13)
Serial.DEC(Depth3)
Serial.tx(13)
Serial.DEC(Depth4)
Serial.tx(13)
Serial.DEC(Depth5)
Serial.tx(13)
Serial.DEC(Depth6)
Serial.tx(13)

Serial.Start(rx, tx, %0000, 9600)
Serial.SetDelimiter("k")
repeat
  Receive := Serial.rx
  if Receive == "o"
    Serial.tx("k")
  Depth1 := Serial.rxDec
  Serial.Dec(FutureD1)
  Depth1 := Serial.rxDec
  Serial.Dec(FutureD2)
  Depth1 := Serial.rxDec
  Serial.Dec(FutureD3)
  Depth1 := Serial.rxDec
  Serial.Dec(FutureD4)
  Depth1 := Serial.rxDec
  Serial.Dec(FutureD5)
  Depth1 := Serial.rxDec
  Serial.Dec(FutureD6)
  eeprom.i2cWritePage(0, $A0, %0000111111110100000, @FutureD1, 1)
  waitcnt(100_000 + cnt) 
  eeprom.i2cWritePage(0, $A0, %0000111111110110000, @FutureD2, 1)
  waitcnt(100_000 + cnt) 
  eeprom.i2cWritePage(0, $A0, %0000111111111000000, @FutureD3, 1)
  waitcnt(100_000 + cnt) 
  eeprom.i2cWritePage(0, $A0, %0000111111111010000, @FutureD4, 1)
  waitcnt(100_000 + cnt) 
  eeprom.i2cWritePage(0, $A0, %0000111111111100000, @FutureD5, 1)
  waitcnt(100_000 + cnt) 
  eeprom.i2cWritePage(0, $A0, %0000111111111110000, @FutureD6, 1)
  waitcnt(100_000 + cnt) 


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

Microsoft: "You've got questions. We've got dancing paper clips."

Comments

  • T ChapT Chap Posts: 4,209
    edited 2007-03-27 22:25
    FutureD1 := 1
    FutureD2 := 108
    FutureD1 := 200
    FutureD2 := 100
    FutureD1 := 150
    FutureD2 := 50

    Should this be FutureD1, FutureD2, FutureD3, FutureD4 etc, instead of D1,D2,D1,D2, D1,D2? I don't see where you established values for D3 - D6 anywhere. Maybe I mised something.

    Post Edited (TChapman) : 3/27/2007 10:48:19 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-27 22:30
    Craig,
    The WAITCNT time is marginal (about 1.2ms at 80MHz clock). It needs to be at least 5ms. If you're concerned about wasting time, use i2cWriteWait which stops waiting when the EEPROM first responds after a write. The comments in the Basic I2C Driver show how to use this routine.
  • crgwbrcrgwbr Posts: 614
    edited 2007-03-28 02:08
    TChapmin, yes it should have been FutureD1 -- FutureD6. This is just a typo in my post, not my real code. Anyway, thanks Mike for the suggestion. I just put in an arrbitrary value for the waitcnt, I figured it would be enough. Time is not a huge issue, so I will put in something like 20_000_000; just for just to be careful.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

    Microsoft: "You've got questions. We've got dancing paper clips."
  • T ChapT Chap Posts: 4,209
    edited 2007-03-28 02:30
    I have some test code that was working fine with Mike's minimal code and the boot EEPROM, if you want to see it I will PM it over. One thing I was doing different, I just used his entire basic routines code for the test, with a few extra routines dropped in.
  • crgwbrcrgwbr Posts: 614
    edited 2007-03-28 02:35
    Just got a second to test out a few changes (like Mike's suggestion). Everything works great!!!!!

    Thanks a lot,
    Craig

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

    Microsoft: "You've got questions. We've got dancing paper clips."
  • KaioKaio Posts: 253
    edited 2007-03-28 12:20
    Craig,

    did you know that you can specify the delay time independent from the clock rate your board is running?

    waitcnt(clkfreq / 5000 + cnt)   'wait for 5 ms
    
    



    This would be also to see clearly to read for others what delay time you want to use.
  • crgwbrcrgwbr Posts: 614
    edited 2007-03-28 23:52
    Kaio, ye sI did know this, but since this program can only run on one freq anyway. Therefore, I figured that it would not be neccisary.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

    Microsoft: "You've got questions. We've got dancing paper clips."
Sign In or Register to comment.