Skip to main content
Visitor II
September 13, 2024
Question

Implementation of SMBus communication in STM32F4 Series

  • September 13, 2024
  • 3 replies
  • 4778 views

Hi ST,

I'm trying to build SMBus Communication in STM32F407 with a battery IC (bq25720), but I can't read the device ID response.
Could you assist me with this?

 

Thanks,

PSR

    This topic has been closed for replies.

    3 replies

    Technical Moderator
    September 13, 2024

    Hello @PSR1 

     

    What is the error you are getting?

    What investigations have you done to find out what's going on?

    Did the address sent by the master is acknowledged by the slave? 

    PSR1Author
    Visitor II
    September 13, 2024

    "I'm transmitting the address using this function:
    HAL_SMBUS_Master_Transmit_IT(&hsmbus1, 0x09 << 2, buff, 2, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC);

    I placed the code to turn on the LED inside the function:
    HAL_SMBUS_MasterTxCpltCallback(SMBUS_HandleTypeDef *hsmbus);

    However, I am unable to receive a response when using the following receive function:
    HAL_SMBUS_Master_Receive_IT(&hsmbus1, 0x09 << 1, buff, 2, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC);"

    could you please help to get the response from Battery IC(BQ25720).

    Thanks & Regards,

    PSR

    Technical Moderator
    September 13, 2024

    Hello @PSR1 

    Is the HAL_SMBUS_MasterTxCpltCallback() get called? 

    If yes, you need to change the XferOptions setting. 

     

    HAL_SMBUS_Master_Transmit_IT(&hsmbus1, SlaveAdress, buff, 2, SMBUS_FIRST_FRAME);
    // Wait for the end of transmit operation
    HAL_SMBUS_Master_Receive_IT(&hsmbus1, SlaveAdress, buff, 2, SMBUS_LAST_FRAME_NO_PEC);

    Why you are using two different addresses for transmit and receive. It is the same slave; the address should be the same. 

    It is mentioned in the slave datasheet that the SMBUS address is 0x12h (0x09h<<1). 

    Saket_Om_1-1726235004279.png

     

    PSR1Author
    Visitor II
    September 16, 2024

    Hi, Saket_om.

    1. I use the same address for master transmit and receive. The receive function is

    Ret = HAL_SMBUS_Master_Receive_IT(&hsmbus1, 0x09<<1, buff, 2, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC);

    If (ret == HAL_OK) {

    LOG_INFO("HAL_SMBUS_Master_Receive_IT:%d%d\r\n",buff[0],buff[1]);

    }

    I'm unable to retrieve the buffer values.

     

    2.How to access various registers of the battery IC (BQ25720) using the SMBus protocol.

    Could you help me?


    Thanks & regards.

    PSR

    Technical Moderator
    September 16, 2024

    Hello @PSR1 

     

    You should use the option SMBUS_LAST_FRAME_NO_PEC and not SMBUS_FIRST_AND_LAST_FRAME_NO_PEC.

    PSR1Author
    Visitor II
    September 16, 2024

    HI Saket,

    I implemented my code based on your suggestion, but scenario is not changed.

    PSR1_0-1726478975766.png

     

    1. In this function Led is Turned on, after that no response from Master_receive _IT function.

    2. also could you please suggest 2nd point from previous query.

     

    Thanks

    PSR

     

     

    Graduate II
    September 20, 2024

    Instead of screenshots of your code, copy and paste using the </> 

     

    PSR1Author
    Visitor II
    September 20, 2024

    Hello @Karl Yamashita,

            Please see the attached bq25720_evm.pdf. I connected L4 series SDA and SCL lines, and everything I did for your information was implemented; please review the logic analyzer output of SMBus lines.

    PSR1_1-1726822211072.png

    PSR1_2-1726822583485.png

     

    Thanks,

    PSR.