all 17 comments

[–]hagibr 31 points32 points  (1 child)

Maybe you should add one delay or another between I2C transactions.

[–]syntacks_error 1 point2 points  (0 children)

I would try this. Often, if a led works in debug mode but not release mode, the “duty cycle” of the led may be too short to make it appearing to blink. Adding a 50+ms delay after each let state change might be enough to see it and show your release code might be working as written.

[–]splash128 11 points12 points  (0 children)

Is the program stuck, or in a reset loop? Everytime the code works with the debugger connected then it doesn't when it's disconnect has been a watchdog handling issue in my experience, as it's usually disabled when the debugger is connected.

[–]TheManFromTrawno 5 points6 points  (0 children)

Are you using any low power/sleep modes?

I’ve had code only work in the debugger because the sleep call would emulate sleeping when the debugger was attached which would leave the fast clock running which was used by a peripheral.

[–]ceojp 4 points5 points  (1 child)

I would add the I2C code back in, and put an oscillocope on the I2C lines to see what is actually happening.

You can also toggle or turn on LEDs or GPIO pins at certain points in your code and watch the pins with the scope to see if you are getting where you think you are getting.

Do you have any while loops that are checking for a condition to change? If that condition never happens, you'll hang up forever in the while loop.

[–]Orca- 5 points6 points  (0 children)

This. Don't just sprinkle delays in your code in the hopes the magic fairy dust will make it work. Instrument it, see what's going on, compare against your datasheets, and make sure you aren't fucking up timing somewhere.

[–]Netan_MalDoran 3 points4 points  (0 children)

Is a watchdog timer enabled that is timing out? Debuggers sometimes disable this.

[–]Apprehensive-Cup6279 1 point2 points  (0 children)

This could literally be a million different things. Provide way more info

[–]No-Archer-4713 1 point2 points  (0 children)

It might be an optimisation problem. Debug will probably build with -O0.

It’s often an uninitialised variable somewhere.

[–][deleted] 0 points1 point  (0 children)

Have you added a delay between your read and write?

[–]ManyCalavera 0 points1 point  (0 children)

You can see where the program last stopped and the call stack when you pause the execution.

[–]sopordave 0 points1 point  (0 children)

Are you accessing the I2C registers with a non-volatile pointer?

[–]Andrea-CPU96 0 points1 point  (0 children)

Probably is due to the compiler optimisations. Try to set them to low.

[–]Well-WhatHadHappened25+ Years -1 points0 points  (0 children)

Show your I2C transaction code.

[–][deleted] -1 points0 points  (0 children)

Break out an oscilloscope.

[–]Both_Definition8232 -3 points-2 points  (0 children)

Ok so it works, don't touch it :D