AnsweredAssumed Answered

I2C: where is data from HAL_I2C_Master_Receive_IT()?

Question asked by garcia.steve on Jan 8, 2016
Latest reply on Jan 9, 2016 by garcia.steve
I'm attempting to read an I2C device with HAL_I2C_Master_Receive_IT().  A logic analyzer shows the data coming across the I2C bus, but where does it go?

This is a st32f405, IAR, and CubeMx generated code.  Given the logic analyzer results, it seems the I2C bus and CubeMx code is fundamentally working.

uint8_t     value8;<br><br>value8 = 0x79;<br>halResult = HAL_I2C_Master_Receive_IT(&hi2c1, (uint16_t)FUEL_GAUGE_I2C_ADDRESS, &value8, (uint16_t)1);<br>

As I read the HAL documentation, the value read from I2C should be placed at value8.  It's not.  What am I missing?

A more complete code block is below.  The initial write is to configure the I2C slave for the following read.  Everything appears correct on the logic analyzer.

    uint16_t tmpValue;<br>    uint8_t     value8;<br>    HAL_StatusTypeDef halResult;<br>    <br>    aTxBuffer[0] = 0x06;    // cmd<br>    aTxBuffer[1] = 0x07;    // cmd<br>    <br>    halResult = HAL_I2C_Master_Transmit_IT(&hi2c1, (uint16_t)FUEL_GAUGE_I2C_ADDRESS, (uint8_t*)&aTxBuffer[0], (uint16_t)2);<br>    if (halResult != HAL_OK)<br>    {<br>        return false;<br>    }<br>    <br>    // Wait for the end of the transfer<br>    // <br>    while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY)<br>    {<br>    } <br>    <br>    HAL_Delay(70);<br>    <br>    // Read result<br>    // <br>    value8 = 0x79;<br>    <br>    halResult = HAL_I2C_Master_Receive_IT(&hi2c1, (uint16_t)FUEL_GAUGE_I2C_ADDRESS, &value8, (uint16_t)1);<br>    if (halResult != HAL_OK)<br>    {<br>        return false;<br>    }<br><br>    tmpValue = (uint16_t)value8;<br>    *value = tmpValue;<br>    <br>    return true;<br>

The result of this block is value8 remains unchanged by the call to  HAL_I2C_Master_Receive_IT.
I've tried various lengths for the I2C read and the result is consistent.  Thre received data doesn't end up where the HAL documentation seems to say it should.