EEprom Nighmare
crgwbr
Posts: 614
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:
··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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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."
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
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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."
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."
did you know that you can specify the delay time independent from the clock rate your board is running?
This would be also to see clearly to read for others what delay time you want to use.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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."