LPC812 Switch Matrix

train tracks

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:


  • TX
  • RX
  • RTS
  • CTS
  • CLK


  • SCK
  • MISO
  • MISO
  • SSEL


  • SDA
  • SCL

SCTimer (0-4):

  • Input
  • Output

Analog Comparator Output
Clock Out

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:

  • ACMP
  • External Crystal in/out
  • SWD
  • Reset
  • 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

  //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 
  //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;

  //disable clock to SWM peripheral

My next post about ARM Cortex-M0.

About Jim Eli

µC experimenter
This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s