I believe this is well documented in the AVR product descriptions for each MCU. AVR is little endian and 8-bit internal architecture. Reading a 16-bit register requires transfer to an intermediate register. LSB must be read first. As this is an internal transfer and potential two 8-bit reads the operation is not atomic. It has to be protected from possible interleaving with ISR (that may also use the intermediate registers), i.e. turning off interrupt handling during the access of the 16-bit register.
If I understand you correctly you are expecting the compiler to resolve this for you? Both the order of the register read (LSB/MSB) but also keeping it atomic??Cheers!
#define TCNT1H_READ ((unsigned char)(TCNT1 >>8))
how about a warning if -Wall or -Wextra was turned on? By the way, is there an easy way to pass such switches to the Arduino IDE?
In Arduino IDE 1.6.4+ you can do:File > Preferences > Compiler Warnings: More for -WallFile > Preferences > Compiler Warnings: All for -Wall -WextraThese are configured in platform.txt.
I am not familiar with Arduino IDE 1.6.4+.
In Arduino IDE 1.6.4 I did did edit platform.txt compiler.warning_level=all, and I was rewarded with warnings... and I cleaned some stuff up as a result. Thanks.
The read of bytes/char TCNT0H or the write of TCNT0L always requires a two-byte access.
Sure seems like something a compiler (or library) would be particularly good at.
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16