Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 11 months ago.
KL25Z read pin control register not possible?
Am I incorrectly reading pin control registers?
Test code:
#include "mbed.h" int main() { unsigned int tmp; printf("PIN ALT STATUS\n"); tmp = (PORTE->PCR[0] & PORT_PCR_MUX_MASK)>>8; printf("PORTE MUX value : )"; printf("%04X\n",tmp); }
The first printf is displayed, the second and third not (lock up at tmp=...?)
1 Answer
10 years, 11 months ago.
Never mind, found the answer on https://mbed.org/forum/mbed/topic/2866/
wrote:
It appears that not all of the peripherals are powered up during the startup of the mbed device.
So, just adding a pin initialisation does the trick.
#include "mbed.h" DigitalIn koko (PTE0); // !! NEEDED BEFORE WE ACCESS PORTE->PCR[0] int main() { unsigned int tmp; printf("PIN ALT STATUS\n"); tmp = (PORTE->PCR[0] & PORT_PCR_MUX_MASK)>>8; printf("%04X\n",tmp); }
We also can check SIM->SCGC5 bits 9..13: these are the Clock Gate Controls for resp. PORTA, PORTB, PORTC, PORTD and PORTE. We cannot read PORTn->PCR[x] when its clock gate bit = 0 (port is not enabled). At startup, only one port is enabled : PORTA.