I am using a slightly modefied i2c library example as my project (https://download.mikroe.com/documents/c ... ibrary.htm), but i aways get the error that SCK is out of the sync and it messes up the whole read/write cycle
The error (the elongation of low period and the contraction of the high period in the last SCK impulse):
And code i am using:
Code: Select all
void main(){
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
PORTB = 0;
TRISB = 0; // Configure PORTB as output
I2C1_Init(50000); // initialize I2C communication
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA0); // send byte via I2C (device address + W)
I2C1_Wr(0x00); // send byte (address of EEPROM location)
I2C1_Wr(0x01); // send data (data to be written)
I2C1_Stop(); // issue I2C stop signal
Delay_100ms();
I2C1_Start(); // issue I2C start signal
I2C1_Wr(0xA0); // send byte via I2C (device address + W)
I2C1_Wr(0); // send byte (data address)
I2C1_Repeated_Start(); // issue I2C signal repeated start
I2C1_Wr(0xA1); // send byte (device address + R)
PORTB = I2C1_Rd(0u); // Read the data (NO acknowledge)
I2C1_Stop(); // issue I2C stop signal
}