assembly - Embedded C: AVR; variable in header cannot be evaluated in main -
thank taking time read.
problem i'm seeing
i have:
main.h
that declares:
uint8_t u_newvar
i have
foo.h
that writes:
extern uint8_t u_newvar
the application sits in infinite while loop in main.c until isr occurs.
in foo.c, said isr calls function within foo.c.
in function (foo_function() if will): 0x01 written u_newvar.
finally, after returning interrupt , infinite while, there single "if" statement:
while(1){ if(u_newvar == 0x01){ uarttx_sendarray(st_uartrx_messagecontents->u_command, (sizeof st_uartrx_messagecontents->u_command)); uarttx_sendbuttonpressdata(st_uartrx_messagecontents->u32_value); u_newvar = 0x00; } }
however, application never enters if. "if" block work if in foo.c, after
u_newvar = 0x01;
line.
stuff tried
i looked @ compiled assembly, , found kind of stumps me.
if @ "if" in main, see:
so loads value address: 0x011d sram, can confirm 0x01.
then "cpi" compare r24 directly 0x01, should work.
then "breq", branch if equal, , increment program counter twice uart function below. makes sense.
however part weird. otherwise, use "rjmp" jump instruction at. unless i'm mistaken, lock here eternity?
so, remember when mentioned when put if block foo.c after write u_newvar? yeah, that's not interesting:
the "if" supposed after "u_newvar = 0x01", compiler smart , optimizes how. why works there.
you forgot tell compiler variable might modified asynchronously. such in isr.
volatile uint8_t u_newvar;
Comments
Post a Comment