cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting when I2C bus becomes IDLE

psusi
Associate II

STM32F302K8 here. According to the manual, there is a flag in the ISR to see if the bus is busy, but it does not generate an interrupt when cleared. Also the STOP condition says it is only generated while you are the master and generate it, or are the previously selected slave. In other words, if another master is talking to another slave on the bus when you want to transmit, you won't get a STOP interrupt when it's done, so how are you supposed to know when the bus is free so you can try to transmit?

4 REPLIES 4
TDK
Guru

I2C_ISR_BUSY can be checked to see if the bus is busy. You can try to send the data you want whenever. If you lose arbitration, an interrupt can be generated and you can try again later.

Edit: same as I2C_SR2_BUSY on the F4

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

Of course... my point is how do you detect when "later" arrives? You need an interrupt when the bus goes idle but apparently the controller can't generate one reliably.

TDK
Guru

There's no interrupt tied to this bit. You just need to check it. Check it in a periodic timer interrupt. Or not, and just send data until it gets through. Those are your options.

You could hack something together with a timer and an EXTI line, but I wouldn't suggest it.

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

Send until it gets through means that the cpu can't service other tasks. A periodic timer means you waste time with an idle bus where you could be sending, but aren't because the timer hasn't fired yet. This is a shame. It seems like a design defect of this I2C controller implementation.