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-20 12:16 AM
Have you checked with an oscilloscope to see if you see data activity?
Do you have pull-ups on the SDA/SCL pins?
Show your schematic of your connections to that IC.
2024-09-20 12:23 AM
Instead of screenshots of your code, copy and paste using the </>
2024-09-20 01:59 AM
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.
Thanks,
PSR.
2024-09-20 02:13 AM
(uint8_t*)CMD_ID
Oops, not a good idea. Consider:
uint8_t cmd_id = CMD_ID;
&cmd_id
2024-09-20 02:23 AM
Hello @PSR1
The value of ret is 2 which mean that the peripheral is busy when calling HAL_SMBUS_Master_Receive_IT().
The first transaction is not already finished.
Hier you are calling interrupt process, so your log should be placed in the complete call back function.
// 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;
void TxComplete_Callback(SMBUS_HandleTypeDef *hsmbus);
void RxComplete_Callback(SMBUS_HandleTypeDef *hsmbus);
void Error_Callback(SMBUS_HandleTypeDef *hsmbus);
void Init_SMBUS_Callbacks(SMBUS_HandleTypeDef *hsmbus)
{
HAL_SMBUS_RegisterCallback(hsmbus, HAL_SMBUS_TX_COMPLETE_CB_ID, TxComplete_Callback);
HAL_SMBUS_RegisterCallback(hsmbus, HAL_SMBUS_RX_COMPLETE_CB_ID, RxComplete_Callback);
HAL_SMBUS_RegisterCallback(hsmbus, HAL_SMBUS_ERROR_CB_ID, Error_Callback);
}
main
{
Init_SMBUS_Callbacks();
// 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();
}
while(1);
}
void TxComplete_Callback(SMBUS_HandleTypeDef *hsmbus)
{
LOG_INFO("SMBUS Mater Transmitted \r\n" );
if (HAL_SMBUS_Master_Receive_IT(&hsmbus1, DEVICE_ADDRESS<<1, &device_id[0], 2, SMBUS_LAST_FRAME_NO_PEC); != HAL_OK)
{
LOG_INFO("Failed to initiate receive in TX Complete Callback\r\n");
}
}
void RxComplete_Callback(SMBUS_HandleTypeDef *hsmbus)
{
LOG_INFO("Charger Status : %.2x %.2x\r\n",device_id[0],device_id[1]);
}
void Error_Callback(SMBUS_HandleTypeDef *hsmbus)
{
uint32_t errorCode = HAL_SMBUS_GetError(&hsmbus1);
printf("SMBus Error: %lu\n", errorCode);
}
Please try with this implementation.
2024-09-20 03:23 AM
Hello @Saket_Om,
Thank you for your response. I attempted to implement the above code; but,
HAL_SMBUS_RegisterCallback
is not enabled. How do I enable?
Thanks,
PSR
2024-09-20 03:27 AM
You can enable it from the stm32f4xx_hal_conf.h
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 1U
2024-09-20 05:49 AM
Hello @Saket_Om ,
I’m utilizing
HAL_SMBUS_RegisterCallback(hsmbus, HAL_SMBUS_MASTER_TX_COMPLETE_CB_ID, TxComplete_Callback);
HAL_SMBUS_RegisterCallback(hsmbus, HAL_SMBUS_MASTER_RX_COMPLETE_CB_ID, RxComplete_Callback);
HAL_SMBUS_RegisterCallback(hsmbus, HAL_SMBUS_ERROR_CB_ID, Error_Callback);
instead of this
HAL_SMBUS_RegisterCallback(hsmbus, HAL_SMBUS_TX_COMPLETE_CB_ID, TxComplete_Callback);
SMBus_master_receive_is not acknowledged, with log status FF FF.
Thanks,
PSR.
2024-09-20 06:31 AM
Hello @PSR1
It is the normal sequence according to the reference manual RM0090. A NA bit is sent after the last byte received.
Your SMBUS setup work fine, however, you need to check if you are receiving the good data. If not, you should investigate more.
2024-09-21 12:03 AM
Hi @Saket_Om,
Thank you for your solution.
Which function can I use to read the registers of BQ25720's battery IC?
Thanks,
PSR.