Skip to main content
o239955_stm1
Associate
August 17, 2016
Question

STM32F4 Hal drivers. Problem reading a songle byte with HAL_I2C_Mem_Read_IT

  • August 17, 2016
  • 4 replies
  • 1080 views
Posted on August 17, 2016 at 11:35

Hello,

when I read a single Byte from I2C using the HAL_I2C_Mem_Read_IT function, all following read or write attempts on the same I2C bus fail with HAL_Timeout.

When I run exactly the same code on a STM32F2 (using the F2 HAL Drivers) I have no Problems.

Do you have any idea what could cause this issue?

    This topic has been closed for replies.

    4 replies

    Amel NASRI
    ST Technical Moderator
    August 17, 2016
    Posted on August 17, 2016 at 14:09

    Hi Oli,

    Could you please precise the firmware versions of both STM32Cube Packages that you are using for F2 and F4?

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    arthi
    Visitor II
    August 17, 2016
    Posted on August 17, 2016 at 16:53

    Hi Oli,

    I have the same problem. I am using -STM32CubeF4 Firmware Package V1.0 /01-July-2016 -STM32CubeMX 4.16 The first Interrupt-Callback function will be triggered. So you can generate the Stop manually. This works for me.

    void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c) {
    /* Generate Stop */
    hi2c->Instance->CR1 |= I2C_CR1_STOP;
    hi2c->State = HAL_I2C_STATE_READY;
    }

    Best Regards Kevin
    o239955_stm1
    Associate
    August 19, 2016
    Posted on August 19, 2016 at 14:05

    Hi Kevin,

    thank youthat seems to work great.

    I'm using Firmware package 1.0.

    BTW:

    I found a difference between F2 and F4 HAL Drivers:

    In function

    static

    HAL_StatusTypeDef I2C_Master_ADDR(I2C_HandleTypeDef *hi2c)

    The F2 Driver has the following code:

    else if(hi2c->XferCount == 1U) 
    {
    if(CurrentXferOptions == I2C_NO_OPTION_FRAME)
    {
    /* Disable Acknowledge */
    hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
    if((hi2c->Instance->CR2 & I2C_CR2_DMAEN) == I2C_CR2_DMAEN)
    {
    /* Disable Acknowledge */
    hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
    /* Clear ADDR flag */
    __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
    }
    else
    {
    /* Clear ADDR flag */
    __HAL_I2C_CLEAR_ADDRFLAG(hi2c);
    /* Generate Stop */
    hi2c->Instance->CR1 |= I2C_CR1_STOP;
    }
    }

    The F4 Driver does not have These instructions. As far as I understand this, this code generates a STOP on the I2C bus wenn the last Byte was read. This would be a reason why it works with F2 Drivers but not with F4 Drivers.

    Nesrine M_O
    Associate
    August 24, 2016
    Posted on August 24, 2016 at 13:07

    Hi Oli,

    Thanks for highlighting this issue. I will check it with our development team & come back to you. Sorry for the inconvenience it may bring.

    -Syrine-