Why is that some values are optmised away during debugging? what does that mean?
Nothing is optimised during debugging.
Optimisation occurs during compiling (and some as part of linking).
This has nothing to do with AVR - it applies to compilers in general.
I wrote this tutorial to explain what's going on and how to work around it:
Note that since I wrote that the compiler has added a -Og option that could prove useful.
It means that the variables are not used anywhere or not necessary. Set, perhaps, but not used.
x = 5;
uint8_t y = x;
If "X" is not used elsewhere, this will probably be optimized into
uint8_t y = 5;
Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net
this will probably be optimized into
Making it "volatile" means it will have to exist even if that makes inefficient code. The other option is to reduce the optimisation level. As I say -Og may help.
Do NOT be tempted to "fix" this by using -O0 though!!!
To easily switch for between some settings you could add a macro like:
#define DBG volatile
#define DBG /* Define into empty statement. */
DBG uint8_t Asdf;
Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756
Bunch of old projects with AVR's: http://www.hoevendesign.com
That was intended as a case example, not an exhaustive catalog. But, the subsequent comments should be instructive to the OP and others.
© 2020 Microchip Technology Inc.