> C Language question regarding for MCU programming?

C Language question regarding for MCU programming?

Posted at: 2014-12-18 
The result depends on the CC1 bit and how TIM3_FLAG_CC1 is defined.

Most likely TIM3_FLAG_CC1 is defined with 1 bit set to 1. That bit would be the CC1 bit in the register. So assuming the CC1 bit is bit 2 (0000 0100), the flag would be defined as 0x04.

So assuming the CC1 flag is bit 2:

#define TIM3_FLAG_CC1 0x04

When the TIM3->SR1 register is read (in your while loop) it is ANDED with the above value, so

TIM3->SR1 & TIM3_FLAG_CC1

if the SR1 register contains 0001 1001 when it is read, then anding it with 0000 0100 will result in 0000 0000. Now it is compared to TIM3_FLAG_CC1 which is 0000 0100. If they are not equal the loop keeps going.

Once the SR1 register has bit 2 set (XXXX X1XX) the loop will end.

So to answer your question, YES, every bit in the SR1 register is anded with the TIM3_FLAG_CC1. But because TIM3_FLAG_CC1 most likely has only one bit set, the ONLY bit that will make a difference in the anding is the 2nd bit (using the example above).

Say SR1 contains

0011 1001

0000 0100 anded, gives

0000 0000

if SR1 contains

0111 0101

0000 0100 anded, gives

0000 0100

The statement in the code I am studying is as follows:

While ((TIM3->SR1&TIM3_FLAG_CC1)!=TIM3_FLAG_CC1);

My question is what result does following statement will give 1 or 0 (I guess it is 1 as per looks of the code)

TIM3->SR1&TIM3_FLAG_CC1

and how, please explain if possible.

(TIM3_SR1 is a register with 7 bits in it CC1 is also one of the bit)

I want to understand if every bit in TIM3_SR1 is & (anded) with CC1 bit or how does it work.

Thanks in advance