cancel
Showing results for 
Search instead for 
Did you mean: 

SMBUS bus busy check

Luke_abc
Associate III

Hi,

I have a power management setup with a smart battery, charger Ic and the host msu - all connected on the SMBUS. I am  facing some issues and I doubt that the data on the SMBUS is getting corrupted. The issue is only happening when the MCU tries to access the bus. There are bus traffic on the smbus due to the communication between the charger IC and the smart battery. So, should the MCU check if the bus is idle before initiating a communication on the smbus ? I have also noticed that the clock frequency is different between the communication between the chargerIC and the smart battery (64 KHz), and between the MCU and the charger IC/smartbattery (93 KHz). Can the difference in the clock frequency lead to data corruption ?

Is there an HAL SMBUS api to check if the bus is busy/idle which can be used before accessing the bus ?

I hope the HAL SMBUS library support bus arbitration and should the clock frequency be same for this ?

 

7 REPLIES 7
TDK
Guru

Even if there was a function to check this, it would still lead to a race condition.

What you are describing is a multi-master I2C bus, which is atypical. The STM32H7 can support multi-master configuration. Ensure the other masters in the system also support this.

If you feel a post has answered your question, please click "Accept as Solution".

Hi @TDK , 

Thanks for your reply.

I understand that. Is difference in the clock frequency okay ?

TDK
Guru

It's a little weird, but yes it's okay. I2C is 100 kHz max (or 400 or more), no minimum, and 64 kHz is certainly within that range. SMBUS has a minimum but it's super slow.

If you feel a post has answered your question, please click "Accept as Solution".
Bob S
Principal

I've not used the H7 on SMBus but have used the STM32G4xx in that exact configuration (with smart battery and charger also on the bus).  Yes, the HAL SMBus code SHOULD check for bus activity before it starts transmitting.  And, yes, there could be a race condition if another master starts sending at the same time.  But the I2C address resolution protocol should deal with that.

Do you have clock stretching enabled on your I2C/SMBus port?

Are you using only the stm32h7xx_smbus.c and .h files from the standard HAL repo, or are you also using the AN4502 upper SMBus layer?

Luke_abc
Associate III

Thank you @Bob S and @TDK  for your replies.

"Yes, the HAL SMBus code SHOULD check for bus activity before it starts transmitting"

Is it okay to use the api "HAL_SMBUS_IsDeviceReady()" to check the bus activity ?

Do you have clock stretching enabled on your I2C/SMBus port?

  smbus1.Init.NoStretchMode = SMBUS_NOSTRETCH_DISABLE;
I hope the above statement means that the clock stretching is enabled. Could you please confirm ?

I am using stm32h7xx_smbus.c only, not with the upper SMBus Layer.

> Is it okay to use the api "HAL_SMBUS_IsDeviceReady()" to check the bus activity ?

Yes, you should generally do this before calling any other transmission function to verify slaves are correctly connected and responding.

If you feel a post has answered your question, please click "Accept as Solution".
Bob S
Principal

Yes, that should enable clock stretching.

The different I2C clock freqs you see should not cause an issue.  I've seen charger ICs use clocks < 100KHz like you are seeing.

You never said exactly WHAT issue or problem you are having.   So what are you seeing that you don't expect?  Or what are you not seeing that you do expect?  Make sure you check the return values from the HAL SMBus calls.