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