Pin Selection and Pin Mode
Know how to select a specific functionality of a given LPC40xx pin. Know how to select a pin mode.
Every GPIO pin of the LPC40xx is capable of other alternative functionalities. Pin selection is the method by which a user is able to designate the functionality of any given pin. For example, GPIO Pin 0.0 can alternatively be used for CAN channel 1 receive, UART channel 3 transmit, and I2C channel 1 data line.
Figure 1A. LPC40xx User Manual IOCON
Figure 1B. I/O Pin Select Mux (from LPC2148, for illustration purposes only)
In order to select the I2C2_SDA functionality of pin 0.10, one must set bit 1, reset bit 0 & 3 of the IOCON register function field to 010.
// Using LPC40xx.h pointers LPC_IOCON->P0_10 &= ~0b010 // reset all bits of function[2:0] LPC_IOCON->P0_10 |= 0b010; // set the function bit for I2C2
The LPC17xx has several registers dedicated to setting a pin's mode. Mode refers to enabling/disabling pull up/down resistors as well as open-drain configuration. PINMODE registers allow users to enable a pull-up (00), enable pull up and pull down (01), disable pull up and pull down (10), and enable pull-down (11). PINMODE_OD registers allow users to enable/disable open-drain mode.
Figure 2. LPC17xx User Manual PINMODE & PINMODE_OD
Figure 3. LPC17xx User Manual PINMODE0