AnsweredAssumed Answered

STM32F0 I2C HAL Communication with diffrent data frame lengths

Question asked by Adrian Pakosinski on Oct 25, 2017

Hi,

 

I try to implement I2C slave communication based on HAL Library (STM32F070) with another MCU. All functions that interest me include as argument uint16_t Size parameter, for example:

 

HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);

HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size);

 

When I set the maximum buffer size in parameter uint16_t Size, the library stuck in:

 

  /* All data are not transferred, so set error code accordingly */
  if(hi2c->XferCount != 0U)
  {
    /* Set ErrorCode corresponding to a Non-Acknowledge */
    hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
  }

 

So if I receive less data the HAL Library return HAL_I2C_ERROR_AF. It looks like the library functions work only for communication with fixed data frame lengths.

 

It is possible to use HAL libraries when data frame length may vary?

 

Thanks, Adrian

Outcomes