I've been working with some TWI sample code for a 32UC3A. In the TWI Init Routine, I have the following:
// Disable TWI interrupts cpu_irq_disable(); 80002294: d3 03 ssrf 0x10 twi->idr = ~0UL; //idr = Interrupt Disable Register - Write Only. For whatever reason, this MCU has an IDR and an IER Interrupt Disable and Enable Only. 80002296: 3f f9 mov r9,-1 80002298: 99 a9 st.w r12[0x28],r9 //There is also an IMR - Interrupt Mask register, which allows reading of Interrupt Enable/Disable... WTF? // IDR and IER are Write Only // IMR is Read Only twi->sr; // What is this?? Why? "Dummy Read" as noted elsewhere? 8000229a: 78 89 ld.w r9,r12[0x20] //The only affect of doing this is clearing the flags in SR that are "Clear On Read", which include GACC, OVRE, NACK, ARBLST and EOSACC, //NOTHING is done with the read value... See the next statement, r9 get's overwritten without ever being used. //8000229a: 78 89 ld.w r9,r12[0x20] // Reset TWI twi->cr = AVR32_TWI_CR_SWRST_MASK; 8000229c: e0 69 00 80 mov r9,128 800022a0: 99 09 st.w r12[0x0],r9
twi->sr; // What is this?? Why?
8000229a: 78 89 ld.w r9,r12[0x20]
Confuses me. Looking at the compiled code, helped explain WHAT it does, which as far as I can see the only result is that 5 status bits will be cleared when it's read.
What really is throwing me off is the presence of what appears to me to be essentially a line of code comprised of nothing but a variable. I conducted another test, with a single lone variable on a line (that wasn't associated with a register), and everything still compiled fine. However, no corresponding machine instruction was generated for it.
Can anyone offer some insight into this situation? What it means to have nothing but a variable on a single line, why one case generates code that reads a register, and the other nothing?
I'm using Atmel Studio 6.1, AVR/GNU Toolchain