1
votes

I am trying to program an STM32f10xx MCU and trying to set the Clock. In the Reference manual It is written that the PLL when turned on, a flag will be set by the hardware indicating that it is ready or LOCKED, The flag bit is called PLLRDY. The PLLRDY is set by hardware to :

1 when the PLL is locked
0 when the PLL is not locked (NOT READY)

the CR register or Control Register's reset value is ZERO by default. and the RCC_CR_PLLRDY = 0x02000000

I need to put a while loop to check if the PLL is ready, is my implementation correct?

  // Turn On PLL
  RCC->CR |= RCC_CR_PLLON;

  // Wait while the PLL "Phase LOCKED LOOP" is Locked and stable:
  // Which is going to be set? the CR itself or the PLLRDY register?
  while( !(RCC->CR & RCC_CR_PLLRDY) )
  {
    // Error when a certain time passes and the PLL is not ready!
  }

or should it be

while( !(RCC->CR | RCC_CR_PLLRDY) )
{
  //SOME CODE!
}


1

1 Answers

1
votes

!(RCC->CR | RCC_CR_PLLRDY) this will be always false as RCC_CR_PLLRDY is not zero and non_zero | any_value is always not zero.

To test if some bits are set you need to use & operator.

The first solution is OK