View previous topic :: View next topic |
Author |
Message |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 09, 2007 9:21 am |
|
|
-1 is displayed because we use the %d specifier, better would have been to use %u because the variables are of the unsigned type. With %d the output will be 255.
-1 or 0xFF is a common default value for empty EEPROMs. It looks like the data is not written to the EEPROM. What is the type number of the EEPROM you are using?
Try replacing the delay_ms(5) in write_ext_eeprom() by Code: | int8 status;
.
.
.
// delay_ms(5);
do
{
i2c_start();
status=i2c_write(0xAE);
} while (status != 0); |
|
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Thu Aug 09, 2007 9:26 am |
|
|
Didn't you change the structure accesses?
should be
etc, as ckielstra correctly advised.
-1's means you are reading FF (i.e blank values) from the EEPROM. |
|
|
eeprom_programmer* Guest
|
|
Posted: Thu Aug 09, 2007 10:22 am |
|
|
Sorry I changed the structure access probably just posted the wrong code.
I am using a 24L128 eeprom, Both Line pulled up to 5v through a resistor |
|
|
Eeprom_programmer
Joined: 07 Aug 2007 Posts: 24
|
|
Posted: Thu Aug 09, 2007 10:31 am |
|
|
Thank you so much, ckielstra AND Set!
It finally works!
%d was the fault!!! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 09, 2007 11:34 am |
|
|
I'm happy for you the code is working. It's just that I can't imagine the simple %u change makes it work. With %u the output should have been 255. Now the behavior is not consistent and that gives me a bad feeling.
I can't find the specifications for an 24L128 so I had a look at the Microchip 24LC128. This chip has a write time of max. 5ms, the same as your delay in the write routine. I wouldn't design my program so tight to the specifications from the datasheet as it gives no room for error. Why not improve your write routine with my suggestion above? With the dynamic test you will never wait any longer than nescessary. |
|
|
Eeprom_programmer
Joined: 07 Aug 2007 Posts: 24
|
|
Posted: Fri Aug 10, 2007 5:42 am |
|
|
I totally understand! And i will defenitely do as you suggested! |
|
|
Eeprom_programmer
Joined: 07 Aug 2007 Posts: 24
|
|
Posted: Fri Aug 10, 2007 6:12 am |
|
|
The values was consistent and i received 255, but there was something the matter with my write routine. After fixing it the correct values was returned.
Thanks again for the valuable info! |
|
|
|