AnsweredAssumed Answered

Invalid clock pulse on I2C

Question asked by alouette.alouette on Mar 11, 2015
Latest reply on Mar 13, 2015 by J
I am using microcontroller STM32F107. On reading EEPROM operation with I2C microcontroller gives 7 clock pulses instead required 9. There is fragment of transmitting on picture.

what.PNG

When this cause occured EEPROM receives last bit at first bit of next byte. After this it receives NACK bit and stops transmitting.

There is function reading EEPROM:

01.uint8_t readPage(uint8_t addr, uint8_t * res, uint8_t length)
02.{
03.    if (i2c_waitflag(I2C, I2C_FLAG_BUSY))
04.        return -1;
05.    I2C_AcknowledgeConfig(I2C, ENABLE); 
06.    I2C_GenerateSTART(I2C, ENABLE);
07.    if (i2c_waitevent(I2C, I2C_EVENT_MASTER_MODE_SELECT))
08.        return -1;
09.    DELAY;   //Just delay by cycle
10.    I2C_Send7bitAddress(I2C, APV_ADDR, I2C_Direction_Transmitter); 
11.    if (i2c_waitevent(I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
12.        return -1;
13.    (void)I2C->SR2;   
14.    DELAY;
15.    I2C_SendData(I2C, addr);
16.    if (i2c_waitevent(I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
17.        return -1;
18.    DELAY;
19.     
20.    I2C_GenerateSTART(I2C, ENABLE);
21.    if (i2c_waitevent(I2C, I2C_EVENT_MASTER_MODE_SELECT))
22.        return -1;
23.    DELAY;
24.    I2C_Send7bitAddress(I2C, APV_ADDR, I2C_Direction_Receiver);
25.    DELAY;
26.    if (i2c_waitevent(I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
27.        return -1;   
28.    uint8_t flag = 0;
29.    for (uint8_t i = 0; i < length; i++)
30.    {
31. 
32.        if (i == length - 2)
33.            I2C_AcknowledgeConfig(I2C, DISABLE);
34.        if ((i == 1) && (flag == 0)) {flag = 1; i--;}  //Workarond from ERRATA for last uncorrect byte
35.        if (I2C_GetFlagStatus(I2C, I2C_FLAG_ARLO | I2C_FLAG_BERR | I2C_FLAG_OVR))
36.            return -1;
37.        res[i] = I2C_ReceiveData(I2C);       
38.        if (i2c_waitevent(I2C, I2C_EVENT_MASTER_BYTE_RECEIVED))
39.            return -1;
             DELAY;
43.    }
44.    if (I2C->CR1 & I2C_CR1_STOP)
45.        return -1;
46.    I2C_GenerateSTOP(I2C, ENABLE);
47.    (void)I2C->SR1;
48.    (void)I2C->SR2;
49.    return 0;
50.}

Flags ARLO, BERR, OVR are not raised.

How do I resolve this problem?

Outcomes