Hi!
I managed to cram the bootloader and my application into a mega8...
Now, having some free space in flash, I decided to add an extra feature... so, I wrote a function to check the reset source at startup. I am mainly interested in brown-out and watchdog reset.
Here's the code that works ok:
if(MCUCSR & (1 << 0)) // power-on reset ; // do nothing else if(MCUCSR & (1 << 2)) // brown-out reset brownOut++; else if(MCUCSR & (1 << 3)) // watchdog reset watchDog++; MCUCSR = 0;
... and here's the code that doesn't work ok:
if(MCUCSR & (1 << 2)) // brown-out reset brownOut++; else if(MCUCSR & (1 << 3)) // watchdog reset watchDog++; MCUCSR = 0;
The second version increments (always) "brownOut" variable... [?!?]
I know I'm a little bit "tired" after a few beers (a friend's birthday), but... am I missing smthing here?
BTW: All I could see in the datasheet is:
To make use of the Reset Flags to identify a reset condition, the user should read and then reset the MCUCSR as early as possible in the program. If the register is cleared before another reset occurs, the source of the reset can be found by examining the Reset Flags.
Regards,
Stanley.