Skip to main content
Explorer
January 8, 2024
Question

i2c slave not printing the received data

  • January 8, 2024
  • 4 replies
  • 2504 views

hii, 

i am using stm32 nucleo g0-b1re i am trying to receive data in interrupt mode, but cant figure out what is wrong, i am new to stm32 i2c protocol.

i have used master as nucleo-h743zi2 and transmitting data, but it is not showing anything on minicom.

 

    This topic has been closed for replies.

    4 replies

    ST Employee
    January 8, 2024

    Hello @Rohit007,

    Try this code :

     

     /* USER CODE BEGIN 2 */
     /*##- Put I2C peripheral in reception process ###########################*/
     if (HAL_I2C_Slave_Receive_IT(&hi2c1, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
     {
     /* Transfer error in reception process */
     Error_Handler();
     }
    
     /*##- Wait for the end of the transfer ###################################*/
     /* Before starting a new communication transfer, you need to check the current
     state of the peripheral; if it�s busy you need to wait for the end of current
     transfer before starting a new one.
     For simplicity reasons, this example is just waiting till the end of the
     transfer, but application may perform other tasks while transfer operation
     is ongoing. */
     while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY)
     {
     }
     /* USER CODE END 2 */

     

     Best Regards,

    Pierre

    Rohit007Author
    Explorer
    January 8, 2024

    actually it is not receiving a single bit of data, it is not entering into address callback function.

     

    ST Employee
    January 8, 2024

    Are you aware of this article? It explains what is I2C is and how to use it through examples.

    I advise you to read it if you are new to stm32 I2C protocol. :)

    What is your application ? Who is the master ?

    Rohit007Author
    Explorer
    January 8, 2024

    my application is to read variable amount of data sent by the master. my master is nucleo- h743zi2 it is sending data of variable amount, i.e. if i send 5 byte my slave should read only that much data or if 10 bytes, slave should be ready to read that too.

     

    Visitor II
    July 2, 2025

    Hi Rohit,

    Can you please tell me how you implemented this? I've been trying to receive variable data automatically, without defining the number of bytes to receive each time.

    Super User
    January 8, 2024

    Use a logic analyzer to understand what is happening on the line.

    ST Employee
    January 9, 2024

    Hello @Rohit007,

    Here are some remark about what may happen :

    • Are you sure you are sending the data ? to the right address ? 
    • Have you scoped SDA and SCL ? I advise you to do it
    • Are the HAL functions (Transmit or Receive) return an error or success code ?
    • Can you share more information about your code (config h743zi2  also) and the hardware settings maybe ?

    Best Regards,

    Pierre