How to establish SMBus communication with a smart battery by using STM32Cube FW-F4 V1.25.2 on STM32F429 MCU?
Hi All,
The following is wha I met.
I have a development board with STM32F429 MCU. I'd like to establish SMBus communication to a smart battery with this development board. PH4 and PH5 are used as SCL and SDA output of smbus2.
I used the following APIs from stm32 hal lib.
HAL_SMBUS_Init, HAL_SMBUS_ConfigDigitalFilter, HAL_SMBUS_Master_Transmit_IT, HAL_SMBUS_IsDeviceReady, and HAL_SMBUS_EV_IRQHandler.
Here's the main part of my code:
void SMBus_Init(tI2C_INDEX index)
{
assert(index < eI2C_MAX);
gSMBus_Handle[index].Instance = gI2C_Base[index];
gSMBus_Handle[index].Init.ClockSpeed = 100000; // 100kHz
gSMBus_Handle[index].Init.AnalogFilter = SMBUS_ANALOGFILTER_ENABLE;
gSMBus_Handle[index].Init.OwnAddress1 = 2;
gSMBus_Handle[index].Init.AddressingMode = SMBUS_ADDRESSINGMODE_7BIT;
gSMBus_Handle[index].Init.DualAddressMode = SMBUS_DUALADDRESS_DISABLE;
gSMBus_Handle[index].Init.OwnAddress2 = 0;
gSMBus_Handle[index].Init.GeneralCallMode = SMBUS_GENERALCALL_DISABLE;
gSMBus_Handle[index].Init.NoStretchMode = SMBUS_NOSTRETCH_DISABLE;
gSMBus_Handle[index].Init.PacketErrorCheckMode = SMBUS_PEC_ENABLE;
gSMBus_Handle[index].Init.PeripheralMode = SMBUS_PERIPHERAL_MODE_SMBUS_HOST;
if (HAL_SMBUS_Init(&gSMBus_Handle[index]) != HAL_OK)
{
while(1);//Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_SMBUS_ConfigDigitalFilter(&gSMBus_Handle[index], 0) != HAL_OK)
{
while(1);//Error_Handler();
}
}
void I2C2_EV_IRQHandler(void)
{
HAL_SMBUS_EV_IRQHandler(&gSMBus_Handle[eI2C2]);
}
When I called HAL_SMBUS_Master_Transmit_IT or HAL_SMBUS_IsDeviceReady, no clock signal was output from PH4 (I used scope to check SCL and SDA signals).
The following is the register values after executing SMBus_Init.
I2C CR1 = 0x003B
I2C CR2 = 0x002D
I2C DR = 0x0000
I2C SR1 = 0x0000
I2C SR2 = 0x0000
I2C CCR = 0x00E1
I2C TRISE = 0x002E
I2C FLTR = 0x0000
Could you tell me what I missed or which part I didn't do correctly, please?