Hello,
I have been writing a program for the FRDM-KV31f board with MCUXPRESSO to derive the clock using the reference manual. In the program I have to loop till a certain bit is set which I am doing with the help of a bitwise operator and a mask. But the program gets stuck in these loops. I am pretty sure that there is some issue with the check condition that I have provided but am not able to figure out what exactly is. Please check the attached and help with the same.
Regards,
Apurv.
Hi
Which loop(s) does it get stuck in?
I would suggest changing checks from
while((MCG->S & 0x20) != 32U)
to
while((MCG->S & 0x20) == 0)
since the method used is (although logically correct) really begging for problems (i.e. is very error-prone).
Also
while((MCG->S) != 8U)
{
//external refrence clock selected
}
should just be looking at the mask location and not the whole register, so will probably fail. More correct is
while((MCG->S & 0x08) == 0)
{
//external refrence clock selected
}
Regards
Mark