Hii all,
I am working on frdm-kl25z EVM and i need I2C0 communication protocol for my task.
I need to communicate with CAT24M01 EEPROM which is I2C based using KEIL IDE.
I used PORTB0 - SCL and PORTB1 - SDA line for my task.
EEPROM has been configured with 4.7k Pull-Up at Vcc side .(I also tried 10k and 1k)
I have configured I2C to work with 100Khz then i tried 400Khz and 1Mhz , my clock freq. is 24 Mhz .
i configured I2Cx_F register to get above baud rate as following.
I2C_F = 0X1E // For 100 Khz
I2C_F = 0x0E // For 400Khz
I2C_F = 0X02 // For 1Mhz respectively.
Now my problem is as below,
I observed following results in my implementation.
1) Sometime it works and writes one byte properly.
2) Sometime it works only after unplugging the power cable of FRDM-KL25Z.
3) Sometime it gets stuck into the getting acknowledgement phase in which i m polling for IICIF flag from I2C_S to be reset (0 value) (The brief is given into code).
I measured the voltages at pin MCU side and EEPROM side and i got 3.3V .
the brief code is attached here.
Please go through it.
Any help on this would be great appreciable.
Thanks & Regards,
Rutvij.
Original Attachment has been moved to: I2C_sample.c.zip
Hello Rutvij:
I checked your code and it seems OK to me, except for the Pause() calls. EEPROM memories have a write cycle time and it seems that you are not providing enough time for it to finish the write process before sending a new command.
Try increasing the pause between write and read.
If this does not work, then it would be useful if you have a scope or logic analyzer to inspect what is going on in the I2C bus. That is the easiest way to debug I2C problems.
Regards!,
Jorge Gonzalez
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------