I2C programming for external EEPROM 24LC256

General discussion on mikroC.
Post Reply
Author
Message
zamani
Posts: 1
Joined: 10 Aug 2010 02:16

I2C programming for external EEPROM 24LC256

#1 Post by zamani » 19 Oct 2010 02:33

Hello,
i have problems in the I2C programming example... THe proteus simulation does not work as per expected. I did compared with the online help and found out also that i'm not able to simulate it in the proteus. here are two different coding for it. For anyone who has expertise in this I2C area, i hope you can help me on this please .. tq vey much...


void write_ext_eeprom(unsigned short highaddress, unsigned short lowaddress,unsigned short data)
{i2c_init(100000);
I2C_Start(); // issue I2C start signal
I2C_Wr(0xA0); // send byte via I2C (24LC256)
I2C_Wr(lowaddress); I2C_Wr(highaddress);
I2C_Wr(data); // send data
I2C_Stop();
}

unsigned short read_ext_eeprom(unsigned short highaddress,unsigned short lowaddress)
{
unsigned short indata;
i2c_init(100000);
I2C_Start(); // issue I2C start signal I2C_Wr(0xA0);
I2C_Wr(0xA0); // send byte via I2C (device address)
I2C_Wr(lowaddress); // send byte (data address)
I2C_Wr(highaddress);
I2C_Repeated_Start(); // issue I2C signal repeated start
I2C_Wr(0xa1); // send byte (device address)
indata = I2C_Rd(0u); // Read the data (NO acknowledge)
return indata;
}

void main(){
PORTB = 0;
TRISB = 0;

write_ext_eeprom(1,0,255); delay_ms(5);

portb=read_ext_eeprom(1,0);

}

and the proteus simulation is


the second coding i use the help online and got the same result...

void main(){
PORTB = 0;
TRISB = 0;

I2C_Init(100000);
I2C_Start(); // Issue I2C start signal
I2C_Wr(0xA2); // Send byte via I2C (command to 24cO2)
I2C_Wr(2); // Send byte (address of EEPROM location)
I2C_Wr(0xF0); // Send data (data to be written)
I2C_Stop();

Delay_ms(100);

I2C_Start(); // Issue I2C start signal
I2C_Wr(0xA2); // Send byte via I2C (device address + W)
I2C_Wr(2); // Send byte (data address)
I2C_Repeated_Start(); // Issue I2C signal repeated start
I2C_Wr(0xA3); // Send byte (device address + R)
PORTB = I2C_Rd(0u); // Read the data (NO acknowledge)
I2C_Stop();
}
Attachments
Proteus Sim.JPG
Proteus Sim.JPG (118.25 KiB) Viewed 1659 times

Post Reply

Return to “mikroC General”