While condition with & bitwise of PINx read I was looking into ATmega32u4 datasheet to configure the SPI, and there is initialization snippet for data transmission.

void SPI_MasterTransmit(char cData)
{
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR &amp; (1&lt;&lt;SPIF)));
}


What I didn't quite get is the last line of the snippet with the while condition to check the state of the SPIF bit in SPSR register.

What I think I understand that it means, if SPIF bit with the a conditional value of 1 which would be in the ALU for comparing it with the actual bit state in SPSR. If this is true with &amp; bitwise operator which would be true if the actual bit in the SPSR is set with the given value (1 &lt;&lt; SPIF).

My questions:


Am I understanding it right?
What this line actually means?
I have removed the semicolon at the end of the line and it compiled OK! Is what I did OK?
SPI transmitt is started by writing one Byte into SPDR. And this code won't return from SPI_MasterTransmit function before it's complete. Transmitt completition is anounced by setting SPIF by hardware (and if SPI interrupt and global interrupts are enabled, it'll run also ISR and clear that flag).

If you write into SPDR before transmission is completed you'll corrupt current "transaction", so you have to wait until it's complete before another write.

Bitwise &amp; is used for bit masking. Bits in the result are set if bits at corresponding positions in arguments are both set:

0b00110011
         &amp;
0b00100001
        ==
0b00100001


So if bit at position SPIF is not set, it will loop again and when it's set, it exits the loop, as there is inverted logic.

( SPSR     &amp; (1&lt;&lt;SPIF))                    !(SPRS &amp;(1&lt;&lt;SPIF))
0b0xxxxxxx &amp; 0b10000000 == 0b00000000  =&gt;  !0b00000000 == true
0b1xxxxxxx &amp; 0b10000000 == 0b10000000  =&gt;  !0b10000000 == false