One unique feature of the LPC8xx µC is the ability to swap pin functions. Want an UART TX on pin #10 and RX on #2? No problem. You can assign the pin functions via the Switch Matrix. This allows great flexibility when performing PCB layout. The Switch Matrix allows the flexible selection of the following peripheral pins:
Analog Comparator Output
Additionally, the Switch Matrix allows for turning fixed-pin functionality off if not needed. This frees up pins for alternate functionality. The following functions can be selected:
- External Crystal in/out
- Clock in/out
NXP produces both an online and downloadable version of LPC Initializer and Pin-muxing Tool. These are great tools for learning about and using the LPC Switch Matrix and I/O functions. There is even a video tutorial about using the tool.
Here is the code I used to inactivate the pull-up/down functions on PIO0s 8 and 9, then turn on the external crystal functionality (XTALIN and XTALOUT). The code then enables CLKOUT functionality on PIO01. This allowed me to connect a 20MHz crystal to the LPC812 to feed the PLL, and measure the clock frequency via the clock-out pin. Cool!
//enable clock to SWM peripheral SYSCON_SYSAHBCLKCTRL |= (1<<SWM); //disable pull-up/down on pio08/9 reg = IOCON_PIO0_8 & ~(0x3<<3); IOCON_PIO0_8 = reg | (0x0<<3); reg = IOCON_PIO0_9 & ~(0x3<<3); IOCON_PIO0_9 = reg | (0x0<<3); //enable XTALIN & XTALOUT on PIO08 & PIO09 PINENABLE0 &= ~((1<<(uint32_t)4) | (~0x1ff)); PINENABLE0 &= ~((1<<(uint32_t)5) | (~0x1ff)); //feed PLL from external crystal bypassing sys osc SYSCON_SYSOSCCTRL |= 1; //configure PIO01 with pull-up reg = IOCON_PIO0_8 & ~(0x3<<3); IOCON_PIO0_8 = reg | (0x0<<3); //assign CLKOUT to PIO0_1 reg = PINASSIGN8 & (~(0xff<<0x10)); PINASSIGN8 = reg | (0x01<<0x10); /* IRC 0 //Internal oscillator for CLKOUT SYSOSC 1 //System oscillator for CLKOUT WDTOSC 2 //Watchdog oscillator for CLKOUT MAINSYSCLK 3 //Main system clock for CLKOUT */ //set CLKOUT source & divider SYSCON_CLKOUTSEL = (uint32_t)3; SYSCON_CLKOUTUEN = 0UL; SYSCON_CLKOUTUEN = 1UL; SYSCON_CLKOUTDIV = 1; //disable clock to SWM peripheral SYSCON_SYSAHBCLKCTRL &= ~(1<<SWM);
My next post about ARM Cortex-M0.