Page 1 of 1

writing and reading to an external eeprom

Posted: Sun Mar 18, 2012 10:01 pm
by Darren.Smith
hi guys, guess what i am a little stuck again, what i am trying to do is write to an external eeprom via i2c, i know i need to start with

start
i2c addres of 0xa0
data
stop

what i need to do is write 8 different variables to the eeprom
my question is would i start as address 0x00 >>8 for each variable. i have been looking thru the data sheet but it does not show a start addr for the eeprom
from what i can work out a page on the eeprom would be 1 variable (8 bit's= 255)
is this correct or am i missing something...
cheers
dazza

Re: writing and reading to an external eeprom

Posted: Mon Mar 19, 2012 12:48 am
by kersing
Darren,

It would help if you specified which eeprom you are trying to use. What is the manufacturer and what is the type?

Looking at the Microchip 24AA08 (random example) you would need to send (for byte write):
start
10100BB0b where BB is a two bit page address
(wait for ack)
word address <-- to address one of the 256 memory locations within the selected page
(wait for ack)
data
(wait for ack)
stop

Regards,

Jac

Re: writing and reading to an external eeprom

Posted: Mon Mar 19, 2012 10:52 am
by Darren.Smith
hi jac,
thank you for your reply, my apologies, i was thinking of using a 24lc02 by microchip. this has only one page of 256 bytes.

Re: writing and reading to an external eeprom

Posted: Mon Mar 19, 2012 11:28 am
by kersing
According to the datasheet the sequence is as I posted in the previous message. Just use 00 for BB (block address). (Actually any value is valid as the block address bits are 'don't care')

So to write a single byte:
start
10100000b
(wait for ack)
word address <-- to address one of the 256 memory locations within the selected page
(wait for ack)
data
(wait for ack)
stop

The easiest way to write 8 variables is to create a write to memory macro and call it 8 times with the values of the different variables and a unique address. The eeprom has 256 bytes memory (addressable with the word address)

Re: writing and reading to an external eeprom

Posted: Mon Mar 19, 2012 12:47 pm
by Darren.Smith
cheers,
it makes sense to me now. would having a mcp23008 on the i2c bus as well change anything, as they need to be addressed on the a0-a2 pins, i think that is what confused me that the eeprom does not get addressed in this way.

cheers
darren

Re: writing and reading to an external eeprom

Posted: Mon Mar 19, 2012 11:25 pm
by kersing
Hi Darren,

The 24xx02 devices do not use the A0-A2 address lines so sharing the bus with another device can result in problems. Because the control bytes for the two devices you've mentioned differ you should be able to use them both on the same bus. In general the safest option for multiple devices on the same bus would be to use only devices using the address lines, for the 24xx02 an alternate device would be the 34xx02.

Good luck,

Jac

Re: writing and reading to an external eeprom

Posted: Tue Mar 20, 2012 1:05 am
by Darren.Smith
thank you kindly for your help jac, much appreciated

cheers
darren

Re: writing and reading to an external eeprom

Posted: Mon Mar 26, 2012 2:19 pm
by Darren.Smith
hi guys, am back again...got everything working up to address 255 on the eeprom, at the moment i am using a 24c32 which has 4096 address's, how do i address above 255 do i need to use a 16 bit pic as i am only using a 8 bit pic at the moment????

Re: writing and reading to an external eeprom

Posted: Mon Mar 26, 2012 2:56 pm
by Benj
Hello Darren,

You should be able to use addresses over 255 on a 8-bit PIC no problem. One thing you may have to do is use a 16-bit variable to work out the address and then split it into high and low address bytes to send to the EEPROM device.

eg.

Int_Address = 256

Byte_Address_High = (Int_Address >> 8 ) & 0xFF
Byte_Address_Low = Int_Address & 0xFF

Re: writing and reading to an external eeprom

Posted: Mon Mar 26, 2012 3:33 pm
by Darren.Smith
cheers ben, will give that a go

Re: writing and reading to an external eeprom

Posted: Tue Mar 27, 2012 1:16 pm
by Darren.Smith
hi ben, that worked great, except i have now lost the count below 256, i must be doing something very stupid here.
cheers
Dazza