CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help with 24c256

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rfreddy



Joined: 03 Jun 2007
Posts: 7

View user's profile Send private message

Help with 24c256
PostPosted: Sun Jun 03, 2007 7:52 am     Reply with quote

Hi!, I'm writing an application which uses 8 24c256 I2C EEPROM. I was only able to write in one of them, but all my efforts to write in the others were unsucessful. I know the logic address must match physical address and must follow its control code which is 1010 (0xA?), but when I change the number after the control code my applicattion hangs.

Anybody can show me a working code which uses several of these memories?

Thanks in advance.

Freddy.
Ttelmah
Guest







PostPosted: Sun Jun 03, 2007 9:59 am     Reply with quote

Remember that on these devices (and on I2C devices in general), the 8bit value here, is setup as:

4bit control code: 3bit address: 1bit R/W

You must not change the bottom bit, and the value on the A0 to A2 lines needs to match the 3bit address. So, if you have the lines wired with 001 (a 1 on A0 only), then the address byte has to change to:

1010 001 0

So you need to double the 'address', before combining it with the byte, or the address will not be understood, and the chip won't respond.

Best Wishes
caduhitec



Joined: 06 Feb 2007
Posts: 3

View user's profile Send private message

PostPosted: Sun Jun 03, 2007 11:44 am     Reply with quote

hi dear,
I gesst this way it´s work, let me know.

BOOLEAN I2C_ready(BYTE device) // Possible to device is 0 to 7
{
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(0xA0 | device << 1); // then the device is ready.
i2c_stop();
return !ack;
}

void i2c_write_byte(BYTE device, long int address, BYTE data) // Possible to device is 0 to 7
{
short int status;

disable_interrupts(GLOBAL);
i2c_start();
i2c_write(0xA0 | device << 1);
i2c_write((address >> 8) &0x1f);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status = i2c_write(0xA0 | device << 1);
while (status == 1)
{
i2c_start();
status = i2c_write(0xA0 | device << 1);
}
i2c_stop();
enable_interrupts(GLOBAL);
}

BYTE i2c_read_byte(BYTE device, long int address) // Possible to device is 0 to 7
{

BYTE data;

disable_interrupts(GLOBAL);
i2c_start();
i2c_write(0xA0 | device << 1);
i2c_write((address >> 8) &0x1f);
i2c_write(address);
i2c_start();
i2c_write(0xA1 | device << 1);
data = i2c_read(0);
i2c_stop();
enable_interrupts(GLOBAL);

return (data);
}
rfreddy



Joined: 03 Jun 2007
Posts: 7

View user's profile Send private message

Re: Help
PostPosted: Mon Jun 04, 2007 11:43 am     Reply with quote

Hi, thank you both for your timely answers. The code worked great!.

Freddy.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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