7 years, 10 months ago.

Cannot print PCR on k64f

I am trying to print PCR as an 8 digit hex number, however the program hangs and never prints the variable.

What is wrong?

Here is a simple test that does not complete

#include "mbed.h"
#include "MK64F12.h"
#include "system_MK64F12.h"


Serial pc(USBTX, USBRX);

int main()
{
    pc.baud(115200);
    pc.printf("Starting...\r");
    pc.printf("System core clock: %luhz\r", (unsigned long)SystemCoreClock);
    pc.printf("TEST : %08X \r", 0b110010010110);
    pc.printf("PORTC->PCR[8] : %08X\r", PORTC->PCR[8]);
	
    wait(2);
    
    return -1;
    
}

Serial Output

Starting...
System core clock: 120000000hz
TEST : 00000C96 

1 Answer

7 years, 10 months ago.

PORTC is unclocked, and at least on (legacy) Freescale MCUs this result in a complete lock of your MCU.

This is done somewhere in the SIM SCG register. For some others at least it is:

SIM->SCGC5 |= 1 << SIM_SCGC5_PORTC_SHIFT;

But I don't know if this is also correct for yours. Alternatively just make a random DigitalIn/Out pin and it will enable the clock.

Accepted Answer

Perfect, Thank you!

posted by Marcus Lee 11 Jan 2017