2024-09-13 12:05 AM
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
2024-09-13 01:53 AM - edited 2024-09-13 01:55 AM
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?
2024-09-13 03:37 AM
"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
2024-09-13 06:45 AM
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).
2024-09-15 11:12 PM
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
2024-09-16 01:46 AM
Hello @PSR1
You should use the option SMBUS_LAST_FRAME_NO_PEC and not SMBUS_FIRST_AND_LAST_FRAME_NO_PEC.
2024-09-16 02:30 AM
HI Saket,
I implemented my code based on your suggestion, but scenario is not changed.
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
2024-09-16 02:42 AM
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]);
2024-09-19 08:13 AM - edited 2024-09-19 08:37 AM
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.
2024-09-19 11:13 PM
Hello @Saket_Om ,
Thank you for the insight. I tried the aforementioned snippet. Could you possibly review my code and log?
Could you kindly assist me develop?
Thanks,
PSR