retepsnikrep
- 13th July 2010, 08:02
I'm experiencing a problem with a corrupt byte in my AT24C512B 512K (65,536 x 8) eeprom code.
TempRom: 'Read & Store 2 x I2C DS18B20 Temp Sensor Rom Codes
debug 27,67,"Ins 1st sensor",10,13,"Any key to scan" 'Video Display
pause 2000 'Pause for 2 seconds
LoopA: 'Loop here to wait for button press
gosub MenuButtons 'Gosub MenuButtons gets button data (0,1,2,3,4,5 = no button) in VarC2
If VarC2 = 5 then LoopA 'If no button pressed goto loopA
OWOUT DigitalTemp, 1, [$33] 'Issue Read ROM command
OWIN DigitalTemp, 0, [STR I2C1\8] 'Read 64-bit device data into the 8-byte array "I2C1"
debug 27,67,"Ins 2nd sensor",10,13,"Any key to scan",10,13 'Video Display
pause 2000 'Pause for 2 seconds
LoopB: 'Loop here to wait for button press
gosub MenuButtons 'Gosub MenuButtons gets button data (0,1,2,3,4,5 = no button) in VarC2
If VarC2 = 5 then LoopB 'If no button pressed goto loopB
OWOUT DigitalTemp, 1, [$33] 'Issue Read ROM command
OWIN DigitalTemp, 0, [STR I2C2\8] 'Read 64-bit device data into the 8-byte array "I2C2"
'Save 2 x I2C Temp sensor data into first 16 bytes of AT24C512B External EEPROM
VarA = 1
I2CWRITE Scdeeprom,Sckeeprom,AT24C512B,VarA,[STR I2C1\8] 'Load data into I2c eeprom
pause 10 'Pause for 10ms
VarA = 9
I2CWRITE Scdeeprom,Sckeeprom,AT24C512B,VarA,[STR I2C2\8] 'Load data into I2c eeprom
For VarA = 1 to 16 'Load I2C1 data from eeprom
I2CREAD Scdeeprom,Sckeeprom,AT24C512B,VarA,[VarB1] 'Read data from I2c eeprom
DEBUG HEX2 VarB1," "
Next VarA
The code allows a user to connect two DS18B20 temp sensors in turn to the input, the program reads and then stores the device data into the external eeprom.
This data is then used elsewhere to facilitate the reading of the sensors when both are connected at the same time. This works fine If i manually type in the device data.
I added some check code to simply display what was stored in the eeprom immediately after the devices had been interogated, and this shows that the first byte of sensor 1 is being corrupted and always returns a $10. I tried moving the data store up a byte to avoid the eeprom first location and data is still corrupted on return.
So in esscence the code works for the sensor 2 and that is stored correctly, but for the first sensor the first byte is always $10 the rest of the 8 bytes for that sensor is fine?
Very strange and ideas?
Could it be something to do with the device needing a dummy write before it can start reading?
From the data sheet
RANDOM READ: A random read requires a “dummy” byte write sequence to load in the data
word address. Once the device address word and data word address are clocked in and
acknowledged by the EEPROM, the microcontroller must generate another start condition. The
microcontroller now initiates a current address read by sending a device address with the
Read/Write select bit high. The EEPROM acknowledges the device address and serially clocks
out the data word. The microcontroller does not respond with a “0” but does generate a following
stop condition
TempRom: 'Read & Store 2 x I2C DS18B20 Temp Sensor Rom Codes
debug 27,67,"Ins 1st sensor",10,13,"Any key to scan" 'Video Display
pause 2000 'Pause for 2 seconds
LoopA: 'Loop here to wait for button press
gosub MenuButtons 'Gosub MenuButtons gets button data (0,1,2,3,4,5 = no button) in VarC2
If VarC2 = 5 then LoopA 'If no button pressed goto loopA
OWOUT DigitalTemp, 1, [$33] 'Issue Read ROM command
OWIN DigitalTemp, 0, [STR I2C1\8] 'Read 64-bit device data into the 8-byte array "I2C1"
debug 27,67,"Ins 2nd sensor",10,13,"Any key to scan",10,13 'Video Display
pause 2000 'Pause for 2 seconds
LoopB: 'Loop here to wait for button press
gosub MenuButtons 'Gosub MenuButtons gets button data (0,1,2,3,4,5 = no button) in VarC2
If VarC2 = 5 then LoopB 'If no button pressed goto loopB
OWOUT DigitalTemp, 1, [$33] 'Issue Read ROM command
OWIN DigitalTemp, 0, [STR I2C2\8] 'Read 64-bit device data into the 8-byte array "I2C2"
'Save 2 x I2C Temp sensor data into first 16 bytes of AT24C512B External EEPROM
VarA = 1
I2CWRITE Scdeeprom,Sckeeprom,AT24C512B,VarA,[STR I2C1\8] 'Load data into I2c eeprom
pause 10 'Pause for 10ms
VarA = 9
I2CWRITE Scdeeprom,Sckeeprom,AT24C512B,VarA,[STR I2C2\8] 'Load data into I2c eeprom
For VarA = 1 to 16 'Load I2C1 data from eeprom
I2CREAD Scdeeprom,Sckeeprom,AT24C512B,VarA,[VarB1] 'Read data from I2c eeprom
DEBUG HEX2 VarB1," "
Next VarA
The code allows a user to connect two DS18B20 temp sensors in turn to the input, the program reads and then stores the device data into the external eeprom.
This data is then used elsewhere to facilitate the reading of the sensors when both are connected at the same time. This works fine If i manually type in the device data.
I added some check code to simply display what was stored in the eeprom immediately after the devices had been interogated, and this shows that the first byte of sensor 1 is being corrupted and always returns a $10. I tried moving the data store up a byte to avoid the eeprom first location and data is still corrupted on return.
So in esscence the code works for the sensor 2 and that is stored correctly, but for the first sensor the first byte is always $10 the rest of the 8 bytes for that sensor is fine?
Very strange and ideas?
Could it be something to do with the device needing a dummy write before it can start reading?
From the data sheet
RANDOM READ: A random read requires a “dummy” byte write sequence to load in the data
word address. Once the device address word and data word address are clocked in and
acknowledged by the EEPROM, the microcontroller must generate another start condition. The
microcontroller now initiates a current address read by sending a device address with the
Read/Write select bit high. The EEPROM acknowledges the device address and serially clocks
out the data word. The microcontroller does not respond with a “0” but does generate a following
stop condition