cancel
Showing results for 
Search instead for 
Did you mean: 

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

zeynepdicle
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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()
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
TDK
Guru

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()
If you feel a post has answered your question, please click "Accept as Solution".

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);
TDK
Guru

Why are you calling HAL_I2C_EnableListen_IT?

Perhaps go off of a known working example:

https://github.com/STMicroelectronics/STM32CubeL4/blob/93f2cde30d17996651d7b31f7091ab3dfe2f99bb/Projects/NUCLEO-L432KC/Examples/I2C/I2C_TwoBoards_AdvComIT/Src/main.c

 

If you feel a post has answered your question, please click "Accept as Solution".
res_queen
Associate II

b

zeynepdicle
Associate III