|
|
View previous topic :: View next topic |
Author |
Message |
M0KHZ
Joined: 14 Feb 2008 Posts: 18 Location: Cumbria
|
Multiple EEPROMs on I2C Bus |
Posted: Tue Oct 07, 2008 1:39 am |
|
|
I have two EEPROMs on my I2C bus, the chip select lines are:
EEPROM A – A0 Low, A1 Low, A2 Low
EEPROM B – A0 High, A1 Low, A2 Low
I am able to write and read to EEPROM with:
write_eeprom(pointer,data);
data = read_eeprom(pointer);
My question is which EEPROM is being used (I’m guessing EEPROM A),
if so how do I communicate with EEPROM B?
I’ve been looking at 24512.c and have found no clues.
Kevin – M0KHZ |
|
|
drdelphi
Joined: 22 Apr 2007 Posts: 22 Location: Romania
|
|
Posted: Tue Oct 07, 2008 2:27 am |
|
|
read_eeprom and write_eeprom are reading/writing from/to pic's internal eeprom.
to use two 24512 eeproms, first make sure you connect them properly to the pic and between themselves. that is:
- tie together all their pins except pin 1
- pin 1 of the first eeprom should be tied to ground and pin 1 of the second eeprom to Vcc
- tie pins 2, 3, 4 and 7 to ground
- tie eeproms' clock to PIN_C3 and eeproms' data to PIN_C4 (eg. for pic18f252)
- pull the clock and data lines to vcc through 2k2 resistors
all these being set, you can use the following functions to read and write from both eeproms :
Code: | #ifndef eeCLOCK
#define eeCLOCK PIN_C3
#define eeDATA PIN_C4
#endif
#use i2c(master, fast, sda = eeDATA, scl = eeCLOCK)
void init_ext_eeprom(void) {
output_float(eeCLOCK);
output_float(eeDATA);
}
/*
dev is 0 or 1 (device number)
address is 0 - 65535 for 24512 (512 / 8 = 65536)
returns 1 if write succeeded, 0 otherwise
*/
int write_ext_eeprom(char dev, unsigned int16 address, char data) {
short int status;
char cmd, i2c_timeout;
i2c_timeout = 0;
cmd = 0xa0;
cmd += dev << 1;
i2c_start();
i2c_write(cmd);
i2c_write(address >> 8);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status = i2c_write(cmd);
while(status == 1) {
i2c_timeout++;
if (i2c_timeout > 100) return(0);
i2c_start();
status = i2c_write(cmd);
}
return(1);
delay_ms(10);
}
char read_ext_eeprom(char dev, unsigned int16 address) {
char data, cmd;
cmd = 0xa0;
cmd += dev << 1;
i2c_start();
i2c_write(cmd);
i2c_write(address >> 8);
i2c_write(address);
i2c_start();
i2c_write(cmd + 1);
data = i2c_read(0);
i2c_stop();
return(data);
} |
|
|
|
MicroManiac
Joined: 21 Aug 2008 Posts: 34
|
|
Posted: Tue Oct 07, 2008 2:28 am |
|
|
This function writes on the internal EEPROM of the microcontroller not the external ones.
In order to use the external ones, you need to write the I2C functions manually
i think you can find sample code in the code library _________________ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
Albert Einstein |
|
|
M0KHZ
Joined: 14 Feb 2008 Posts: 18 Location: Cumbria
|
|
Posted: Tue Oct 07, 2008 3:17 am |
|
|
Thanks guys, as usual I was doing something stupid
I've checked the schematic and all OK, tonight I'll modify the code and try again, I'll let you know how I get on.
Kevin |
|
|
Guest
|
|
Posted: Tue Oct 07, 2008 12:31 pm |
|
|
All working great
Thanks again guys
Kevin - M0KHZ |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|