I am using I2C and I have earlier posted doubts about I2C here. I am using PIC controllers and using their compiler C18. I used their libraries to build a function to write data in EEPROM via I2C, and when I crosschecked the SCL lines they were fluctuating.
I have made up a function to write to EEPROM but I have missed out on delays as the datasheet says "minimum 5ms delay for each write operation in to I2C is required".
I trust it is causing the troubles. The problem is SCL does not stay at 100kHz and fluctuates between 54kHz and 100kHz but never beyond that. Is that because Control byte,address and data is sent along the function?
float ee_write_float(unsigned char ee_addr, float f)
{
void i2c_init(); //initialize I2c
unsigned char *p = (unsigned char *)&f;
unsigned char i;
for (i = sizeof f; i != 0; --i)
{
EEByteWrite(EE_I2C_ADDR, ee_addr++, *p++);
}
}
How important is the dela for I2C write operations?
Could that be the cause of problem?
Should I put a delay after the EEByteWrite function to compensate?
Noted: the SCL becomes somewhat stable after the baud rate is reduced to 20kHz then it fluctuates between 17kHz and 19kHz. I would be extremely happy if you found out any reasonable cause to fix this trouble..or any valuable suggestions will be welcomed whole heartily.