PDA

View Full Version : Writing and reading to a 24LC1025



Angus Anderson
- 17th April 2007, 14:50
I am developing a weather station logging system uses a 16F877 and should write 16 bytes of daily data to a 24LC512 EEPROM. Using I2C, I have a DS1307 (which works fine) connected on the same bus as the 24LC512. However, I cannot write or read succesfully to the EEPROM at all. the 3 address pins on the 512 are grounded. After trying unsuccessfully to write & read in page mode, I went back to the "Really simple" example in the PBP handbook, which I still cant get to work - instead of reading a 6 back, I get 255

Code below:

'27LC512 READ/WRITE Test
'DS1307 works fine on SCL and SDA pins below.
'24LC512 is in parallel with DS1307


SCL pin VAR PORTC.2
SDApin VAR PORTC.3
B2 var byte

'24LC512 MSB is device code. LSB is device address, all address pins grounded
cont con %10100000

'Writetest:
Lcdout $fe,1:Pause 500
Lcdout $fe,$80,"Mem read/write test"
I2cWrite SDAPin,SCLPin,cont,%00001111,[6] 'Write decimal 6 to address 15
pause 20 'Allow time for write to finish

''----------------------------| Now read it back |--------------------------
I2cread SDAPin,SCLPin,cont,%00001111,[b2] 'Read data at address 15
lcdout $fe,$C0,#B2:Pause 50
Idle:goto Idle
End
I Get 255 returned in B2 instead of decimal 6

Any help gratefully received


Angus Anderson

skimask
- 17th April 2007, 15:02
I am developing a weather station logging system uses a 16F877 and should write 16 bytes of daily data to a 24LC512 EEPROM. Using I2C, I have a DS1307 (which works fine) connected on the same bus as the 24LC512. However, I cannot write or read succesfully to the EEPROM at all. the 3 address pins on the 512 are grounded. After trying unsuccessfully to write & read in page mode, I went back to the "Really simple" example in the PBP handbook, which I still cant get to work - instead of reading a 6 back, I get 255
Angus Anderson

Do a search here on the site for 24LC1025. There was another person awhile back had similar problems with the larger I2C eeproms, got it working with the advice in that thread, something about splitting the address into two seperate bytes in the command line, not really sure.

Angus Anderson
- 17th April 2007, 15:04
Thanks Skimask. Will report back

Jerson
- 17th April 2007, 15:31
This might help you

http://www.picbasic.co.uk/forum/showthread.php?p=34990&highlight=jerson#post34990

Jerson

Dave
- 18th April 2007, 20:58
Angus Anderson, the 24LC1025 is expecting an 16 bit address. You are only sending it an 8 bit address.

Dave Purola,
N8NTA

Angus Anderson
- 20th April 2007, 11:38
Dave, you were right about the 16 bit address

I've managed to solve the problem by:

1) Making the address a word sized variable
2) Changing the pullup resistors from 4k7 to 2k7
3) Taking the data to be stored and saving it Highbyte and Lowbyte so:

I2cWrite SDA,SCL,$A0,Address,[Databyte.Highbyte]
Address = Address+1
I2cWrite SDA,SCL,$A0,Address,[Databyte.Lowbyte]
Address = Address+1

It now works like a charm. Thanks all of you for your advice, not the least by being reminded to take the trouble to do a search of the forum first ;-)

Dave
- 20th April 2007, 11:49
Angus Anderson, That's good you got it working. I use 4 of the 24LC1025's for a fishing device I designed and it records 18+ hours of various data.

Dave Purola,
N8NTA