cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Communication not working in Debug Mode

Adarsh96
Associate

Split from this old, abandoned thread.


I see the same error. I'm using STM32F302, talking to MCF8329A using I2C. I can see the STM32 is reading the MCF8329A perfectly fine with no error when I power cycle it.
But when I run the firmware on debug mode on stmCubeIDE, I see the I2C doesn't respond, it responds with an error from I2C_WaitOnFlagUntilTimeout. 

4 REPLIES 4
TDK
Super User

Probably the bus is in a bad state because the I2C bus was interrupted mid-transaction. A power cycle will clear it.

Put a HAL_Delay(500) before you do anything with the I2C. The debugger resets several times when you start a debug session.

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

Welcome to the forum.

Rather than wake up an old abandoned thread, it's better to start your own - then you can mark the solution when the problem is solved.

You say it's the "same error", but that thread never established what the actual problem was. In fact, the poster never engaged at all beyond asking the rather vague question!

 

You need to give some more details of your setup - please see: How to write your question to maximize your chances to find a solution

 

What, exactly, do you mean by "run the firmware on debug mode" ?

 

Have you used a logic analyser to compare what happens on the I2C wires when it's working against what happens when it fails ?

 

See this for when things work with debug, but not without:

https://community.st.com/t5/stm32-mcus-products/uart-request-response-just-during-debug-and-debugger-connected/m-p/860685/highlight/true#M289492

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

The delay of 500 isn't helping. Before I use the I2C in the firmware, I have asked HAL_I2C_IsDeviceReady(), for which I got a HAL_OK response meaning the I2C is working fine. 
But when I start reading/writing to MCF8329A it fails every time (During debug mode, FYI no breakpoints applied).

Its very curious that it works when I power cycle, with great ease.

Don't expect I2C to work correctly when single-stepping through code. There are timing agreements between master and slave that need to be met. No reason for it not to work in debug mode provide you are not using breakpoints or other things that interrupt the bus.

Show relevant code.

A logic analyzer trace of SCL/SDA would show you what's happening on the line.

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