Pin Selection and Pin Mode

Objective

Know how to select a specific functionality of a given LPC17xx pin. Know how to select a pin mode.

Pin Selection

Every GPIO pin of the LPC17xx 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 by used for CAN channel 1 receive, UART channel 3 transmit, and I2C channel 1 data line. 

 

 

Figure 1A. LPC17xx User Manual PINSEL0

 

Figure 1B. I/O Pin Select Mux (from LPC2148, for illustration purposes only)

In order to select the SDA2 functionality of pin 0.10, one must set bits 21 & 20 of PINSEL0 register to 1 & 0 respectively.

// Using the memory address from the datasheet
*(0x4002C000) &= ~(0x3 << 20);		// Clear bits 20 & 21
*(0x4002C000) |= (0x2 << 20);		// Set bit 21

// Using LPC17xx.h pointers
LPC_PINCON->PINSEL0 &= ~(0x3 << 20);		// Clear bits 20 & 21
LPC_PINCON->PINSEL0 |= (0x2 << 20);			// Set bit 21

Pin Mode

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 

 

Figure 4. LPC17xx User Manual PINMODE_OD0

For example, if one desires to configure pin 0.09 to enable a pull-up resistor and open drain mode, one must clear bits 18 & 19 of PINMODE0 register, and set bit 9 of register PINMODE_OD0.

// Using the memory address from the datasheet
*(0x4002C040) &= ~(0x3 << 18);		// Clear bits 18 & 19
*(0x4002C068) |= (0x1 << 9);		// Set bit 9

// Using LPC17xx.h pointers
LPC_PINCON->PINMODE0 &= ~(0x3 << 18);		// Clear bits 18 & 19
LPC_PINCON->PINMODE_OD0 |= (0x1 << 9);		// Set bit 9

You may find it helpful to automate register setting and/or clearing. Per our Coding Standards, inline functions should be used (not Macros).

 

Figure 5. LPC17xx Pin Registers & Circuit (credit: https://sites.google.com/site/johnkneenmicrocontrollers/input_output/io_1768) 

Back to top