cancel
Showing results for 
Search instead for 
Did you mean: 

Implementation of SMBus communication in STM32F4 Series

PSR1
Associate II

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

19 REPLIES 19
Saket_Om
ST Employee

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? 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

"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

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

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
PSR1
Associate II

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

Hello @PSR1 

 

You should use the option SMBUS_LAST_FRAME_NO_PEC and not SMBUS_FIRST_AND_LAST_FRAME_NO_PEC.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

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

 

 

This part below should be put in the HAL_SMBUS_MasterRxCpltCallback()

 

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

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Hello @PSR1 

 

Could you please try the code snippet below?

 

 

// Define the BQ25720 device address and register address
#define BQ25720_ADDR 0x09
#define CMD_ID 0xFF
uint8_t device_id[2];
SMBUS_HandleTypeDef   hsmbus1;
HAL_StatusTypeDef ret;

// Send the register address
ret =HAL_SMBUS_Master_Transmit_IT(&hsmbus1, (BQ25720_ADDR << 1), (uint8_t*)CMD_ID , 1, SMBUS_FIRST_FRAME);
if (ret != HAL_OK) {
    // Transmission Error
    Error_Handler();
}
// Read the Device ID from the Master TX complete call back
ret = HAL_SMBUS_Master_Receive_IT(&hsmbus1, (BQ25720_ADDR << 1), &device_id[0], 2, SMBUS_LAST_FRAME_NO_PEC);
if (ret != HAL_OK) {
   // Reception Error
   Error_Handler();
 }

 

 

 

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

Could you help me?

The process is mentioned on the device datasheet.

 

Saket_Om_0-1726760086611.png

 

Saket_Om_1-1726760124070.png

 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Hello @Saket_Om ,

Thank you for the insight. I tried the aforementioned snippet. Could you possibly review my code and log?

PSR1_0-1726812567398.png

 

PSR1_1-1726812621370.png

Could you kindly assist me develop?

 

Thanks,

PSR