I2c frequency sync issues

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
HelterSkelter
Posts: 3
Joined: 24 Dec 2017 17:13

I2c frequency sync issues

#1 Post by HelterSkelter » 22 Mar 2018 20:16

Hello,

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):
Image
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
}
Thanks in advance because it is driving me crazy.

Post Reply

Return to “Library Development Discussion”