Skip to main content
Graduate II
December 20, 2023
Solved

The issue with HAL_I2C_EnableListen_IT in I2C Slave Data Transmission using STM-HAL

  • December 20, 2023
  • 4 replies
  • 2823 views

I am using STM32G050 and I also tried with STM32L476. I am transmitting data as an I2C Slave using STM-HAL. However, when I use HAL_I2C_EnableListen_IT, the transmission is an error. I can't read values and see the logic analyzer. HAL_I2C_DisableListen_IT allows successful data transmission. I am trying to understand the underlying reasons for this behavior. Why I can't transmit values?
uint8_t packed1[10] = { 0xAA, 0x01, 0x07, 0x01, 0x12, 0x55, 0x12, 0x01, 0xAA, 0x2B };
uint8_t packed2[10] = { 0xBB, 0x01, 0x07, 0x01, 0x12, 0x55, 0x12, 0x01, 0xAA, 0x2B };

HAL_I2C_EnableListen_IT(&hi2c2);
HAL_I2C_Slave_Transmit(&hi2c2, packed1, 10, HAL_MAX_DELAY);
HAL_Delay(300);

HAL_I2C_DisableListen_IT(&hi2c2);
HAL_I2C_Slave_Transmit(&hi2c2, packed2, 10, HAL_MAX_DELAY);
HAL_Delay(300);i2c-interrupt.PNG

    This topic has been closed for replies.
    Best answer by TDK

    You're not using the library according to the instructions. Don't call HAL_I2C_EnableListen_IT when you're using blocking transfer functions.

     *** Polling mode IO operation ***
     =================================
     [..]
     (+) Transmit in master mode an amount of data in blocking mode using @ref HAL_I2C_Master_Transmit()
     (+) Receive in master mode an amount of data in blocking mode using @ref HAL_I2C_Master_Receive()
     (+) Transmit in slave mode an amount of data in blocking mode using @ref HAL_I2C_Slave_Transmit()
     (+) Receive in slave mode an amount of data in blocking mode using @ref HAL_I2C_Slave_Receive()

    4 replies

    TDKAnswer
    Super User
    December 20, 2023

    You're not using the library according to the instructions. Don't call HAL_I2C_EnableListen_IT when you're using blocking transfer functions.

     *** Polling mode IO operation ***
     =================================
     [..]
     (+) Transmit in master mode an amount of data in blocking mode using @ref HAL_I2C_Master_Transmit()
     (+) Receive in master mode an amount of data in blocking mode using @ref HAL_I2C_Master_Receive()
     (+) Transmit in slave mode an amount of data in blocking mode using @ref HAL_I2C_Slave_Transmit()
     (+) Receive in slave mode an amount of data in blocking mode using @ref HAL_I2C_Slave_Receive()
    Graduate II
    December 21, 2023

    Thank you for answering. 
    When I transmit it like this  I can't transmit it again

     

    HAL_I2C_EnableListen_IT(&hi2c2);
    while (1) {
    HAL_I2C_Slave_Transmit_IT(&hi2c2, packed, 10);
    HAL_Delay(300);
    Super User
    December 21, 2023
    Visitor II
    December 22, 2023

    b

    Graduate II
    December 22, 2023