Page 1 of 1

I2C communication problems with EEPROM

Posted: Fri Sep 14, 2012 12:22 pm
by zadah
Hello

I have tried to get i2c communication work with EEPROM. I have Easy PIC development board with 18f45k22 PIC installed

I have tried both the transmit and transaction components, but it doesnt work. In transmit mode I get ACK messages after every command, but the data from EEPROM in not valid, i get 255 in every case.( I dont know if its transfering at all), I think the PIC cant read the EEPROM now

I have also same problem with Modtronix SBC83IL board, the data doesnt transfer. I have tried many methods and also checked the EEPROM address is correct.



Here is mikroC Pro c code which works fine: ( when I made similar program with flowcode, it doesnt work.)

void main(){
ANSELB = 0; // Configure PORTB pins as digital
ANSELC = 0; // Configure PORTC pins as digital

TRISB = 0; // Configure PORTB as output
LATB = 0; // Clear PORTB

I2C1_Init(100000); // initialize I2C communication
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (address of EEPROM location)
I2C1_Wr(0xAA); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal

Delay_100ms();

I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA2); // send byte via I2C (device address + W)
I2C1_Wr(2); // send byte (data address)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA3); // send byte (device address + R)
LATB = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop(); // issue I2C stop signal
}

Re: I2C communication problems with EEPROM

Posted: Fri Sep 14, 2012 12:32 pm
by Enamul
Hi,
Have you tried the attached example? Here mode is determining read or write..so if you can use switch to move between read and write..or you can simply read first and display in LCD and write then and display in LCD and read back again see whether it's written fine or not..

Re: I2C communication problems with EEPROM

Posted: Fri Sep 14, 2012 1:43 pm
by zadah
Enamul wrote:Hi,
Have you tried the attached example? Here mode is determining read or write..so if you can use switch to move between read and write..or you can simply read first and display in LCD and write then and display in LCD and read back again see whether it's written fine or not..
Hello,

Yes I have also tried that method, but it doesnt work :( Strange thing is that I get ACK (0) return values OK, but the data seems not to transfer.

I dont understand why the simple C code is working OK, but when i make same on Flowcode it doesnt work. Is there some kind of a configuration issues? I have exactly same PIC config values with MikroC and Flowcode.

Re: I2C communication problems with EEPROM

Posted: Fri Sep 14, 2012 3:12 pm
by Enamul
Hi,
Your program has some problem and I have changed the configuration as well. It should work now..Data is what return..If you are receiving only one Byte 1 should be in last byte..

Re: I2C communication problems with EEPROM

Posted: Fri Sep 14, 2012 5:20 pm
by zadah
Thanks, Enamul

I didint notice the problem with Receive_byte component. :oops: I dont still understand meaning of "last" in that component.

I will check it tomorrow how it works.

Re: I2C communication problems with EEPROM

Posted: Sun Sep 16, 2012 9:40 am
by zadah
Yes, It works on both PICs, thanks!

Re: I2C communication problems with EEPROM

Posted: Sun Sep 16, 2012 9:59 am
by Enamul
Hi,
Thanks for letting me know.

Re: I2C communication problems with EEPROM

Posted: Wed Oct 10, 2012 5:57 am
by Mikat
zadah wrote:Thanks, Enamul

I dont still understand meaning of "last" in that component.

I will check it tomorrow how it works.
That is basically the ack byte that the master sends, if it's 0, the transmission will continue, but if it's 1 the slave device knows that it was last byte of the transmission..

Mika