|
|
| Pin Function 3 | Pin Function 2 | Pin Function 1 | Pin Function 0 | Pin Number | Port Number | MBed Pin | MBed Pin | Port Number | Pin Number | Pin Function 0 | Pin Function 1 | Pin Function 2 | Pin Function 3 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Reserved | AD0.6 | RXD0 | GPIO Port 0.3 | 3 | 0 | USB RX |
![]() |
USB TX | 0 | 2 | GPIO Port 0.2 | TXD0 | AD0.7 | Reserved |
| (Gnd) | - | - | 1 | 40 | - | - | 3.3v Regulated (VOUT) | |||||||
| 4.5v-9.0v (VIN) | - | - | 2 | 39 | - | - | 5.0v USB out (VU) | |||||||
| 1.8v-3.3v Battery for RTC (VB) | - | - | 3 | 38 | - | - | USB D- from connector (IF-) | |||||||
| External reset (nR) | - | - | 4 | 37 | - | - | USB D+ from connector (IF+) | |||||||
| MAT2.3 | MOSI1 | I2STX_SDA | GPIO Port 0.9 | 9 | 0 | 5 | 36 | - | - | Ethernet RD- (From DP83848) | ||||
| MAT2.2 | MISO1 | I2STX_WS | GPIO Port 0.8 | 8 | 0 | 6 | 35 | - | - | Ethernet RD+ (From DP83848) | ||||
| MAT2.1 | SCK1 | I2STX_CLK | GPIO Port 0.7 | 7 | 0 | 7 | 34 | - | - | Ethernet TD- (From DP83848) | ||||
| MAT2.0 | SSEL1 | I2SRX_SDA | GPIO Port 0.6 | 6 | 0 | 8 | 33 | - | - | Ethernet TD+ (From DP83848) | ||||
| SDA1 | TXD3 | RD1 | GPIO Port 0.0 | 0 | 0 | 9 | 32 | 0 | 30 | GPIO Port 0.30 | USB_D- | Reserved | Reserved | |
| SCL1 | RXD3 | TD1 | GPIO Port 0.1 | 1 | 0 | 10 | 31 | 0 | 29 | GPIO Port 0.29 | USB_D+ | Reserved | Reserved | |
| MOSI | MOSI0 | DCD1 | GPIO Port 0.18 | 18 | 0 | 11 | 30 | 0 | 4 | GPIO Port 0.4 | I2SRX_CLK | RD2 | CAP2.0 | |
| MISO | MISO0 | CTS1 | GPIO Port 0.17 | 17 | 0 | 12 | 29 | 0 | 5 | GPIO Port 0.5 | I2SRX_WS | TD2 | CAP2.1 | |
| SCK | SCK0 | TXD1 | GPIO Port 0.15 | 15 | 0 | 13 | 28 | 0 | 10 | GPIO Port 0.10 | TXD2 | SDA2 | MAT3.0 | |
| SSEL | SSEL0 | RXD1 | GPIO Port 0.16 | 16 | 0 | 14 | 27 | 0 | 11 | GPIO Port 0.11 | RXD2 | SCL2 | MAT3.1 | |
| CAP3.0 | I2SRX_CLK | AD0.0 | GPIO Port 0.23 | 23 | 0 | 15 | 26 | 2 | 0 | GPIO Port 2.0 | PWM1.1 | TXD1 | Reserved | |
| CAP3.1 | I2SRX_WS | AD0.1 | GPIO Port 0.24 | 24 | 0 | 16 | 25 | 2 | 1 | GPIO Port 2.1 | PWM1.2 | RXD1 | Reserved | |
| TXD3 | I2SRX_SDA | AD0.2 | GPIO Port 0.25 | 25 | 0 | 17 | 24 | 2 | 2 | GPIO Port 2.2 | PWM1.3 | CTS1 | Reserved | |
| RXD3 | AOUT | AD0.3 | GPIO Port 0.26 | 26 | 0 | 18 | 23 | 2 | 3 | GPIO Port 2.3 | PWM1.4 | DCD1 | Reserved | |
| AD0.4 | VBUS | Reserved | GPIO Port 1.30 | 30 | 1 | 19 | 22 | 2 | 4 | GPIO Port 2.4 | PWM1.5 | DSR1 | Reserved | |
| AD0.5 | SCK1 | Reserved | GPIO Port 1.31 | 31 | 1 | 20 | 21 | 2 | 5 | GPIO Port 2.5 | PWM1.6 | DTR1 | Reserved | |
| CAP1.0 | PWM1.1 | USB_UP_LED | GPIO Port 1.18 | 18 | 1 | LED1 | LED4 | 1 | 23 | GPIO Port 1.23 | MCI1 | PWM1.4 | MISO0 | |
| SCK0 | PWM1.2 | MCI0 | GPIO Port 1.20 | 20 | 1 | LED2 | LED3 | 1 | 21 | GPIO Port 1.21 | MCABORT | PWM1.3 | SSEL0 | |
| Pin Function 3 | Pin Function 2 | Pin Function 1 | Pin Function 0 | Pin Number | Port Number | MBed Pin | MBed Pin | Port Number | Pin Number | Pin Function 0 | Pin Function 1 | Pin Function 2 | Pin Function 3 | |
| GPIO (General Purpose Input/Output) | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Uses: |
|
||||||||||||||||||||||||
| Pin Functions | |||||||||||||||||||||||||
| GPIOx.y | General Purpose Input/Output (on port x pin y) | ||||||||||||||||||||||||
| Code | |||||||||||||||||||||||||
| Important headers: |
|
||||||||||||||||||||||||
| Interrupt defines: |
|
||||||||||||||||||||||||
| Useful functions: |
|
||||||||||||||||||||||||
| Example code (GPIO Output): |
#include "lpc_types.h" #include "lpc17xx_gpio.h" // A simple program to move a lit LED back and forth on the four onboard mbed LEDs. void main (void) { // The LPC1768 port 1 pin masks for the individual mbed onboard LEDs. uint32_t led_mask[4] = {1 << 18, 1 << 20, 1 << 21, 1 << 23}; // The LPC1768 port 1 pin mask for all the mbed onboard LEDs. uint32_t all_leds_mask = led_mask[0] | led_mask[1] | led_mask[2] | led_mask[3]; // Set the direction of the pins on Port 1 for the mbed onboard LEDs to output. GPIO_SetDir(1, all_leds_mask, 1); // The number of the LED currently lit. uint8_t led_number = 0; // The direction the lit LED is moving: 0 - left to right, 1 - right to left. uint8_t direction_backwards = 0; // Loop forever. while (1) { // Turn off all LEDs. GPIO_ClearValue(1, all_leds_mask); // Turn on the current LED. GPIO_SetValue(1, led_mask[led_number]); if (!direction_backwards) { // If moving forwards increment led_number until it is the last, then reverse direction. led_number++; if (led_number >= 3) { direction_backwards = 1; } } else { // If moving backwards decrement led_number until it is the first, then reverse direction. led_number--; if (led_number <= 0) { direction_backwards = 0; } } // Count to 2 million to generate a crude delay. uint32_t cycleNo = 0; while (cycleNo < 2000000) { cycleNo++; } } } |
||||||||||||||||||||||||
| I2C (Inter-Integrated Circuit bus/protocol) | |||||||||||||||||||||||||
| Uses: |
|
||||||||||||||||||||||||
| Notes: |
|
||||||||||||||||||||||||
| I2C addresses: |
|
||||||||||||||||||||||||
| Pin Functions | |||||||||||||||||||||||||
| SDAx | I2C Serial DAta for I2C device x | ||||||||||||||||||||||||
| SDAx | I2C Serial CLock for I2C device x | ||||||||||||||||||||||||
| Code | |||||||||||||||||||||||||
| Important headers: |
|
||||||||||||||||||||||||
| Device struct defines: |
|
||||||||||||||||||||||||
| Interrupt defines: |
|
||||||||||||||||||||||||
| Example code (Polling hex keypad): |
#include "LPC17xx.h" #include "lpc_types.h" #include "lpc17xx_pinsel.h" #include "lpc17xx_i2c.h" #define KEYPAD_I2C_ADDRESS (0x42) void main (void) { /* Configure Pins */ PINSEL_CFG_Type PinCfg; PinCfg.Funcnum = PINSEL_FUNC_3; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Portnum = I2C_SCL_SDA_PORT; PinCfg.Pinnum = I2C_SDA_PIN; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = I2C_SCL_PIN; PINSEL_ConfigPin(&PinCfg); // Configure I2C to run at 100000Hz I2C_Init(I2CDEV, 100000); // Enable the I2C device I2C_Cmd(I2CDEV, ENABLE); uint8_t data_out = 0x0F; uint8_t data_in = 0x00; I2C_M_SETUP_Type i2c_m_setup; i2c_m_setup.sl_addr7bit = KEYPAD_I2C_ADDRESS >> 1; i2c_m_setup.tx_data = &data_out; i2c_m_setup.tx_length = sizeof(data_out); i2c_m_setup.rx_data = &data_in; i2c_m_setup.rx_length = sizeof(data_in); i2c_m_setup.retransmissions_max = 3; Status i2c_status = I2C_MasterTransferData(I2CDEV, &i2c_m_setup, I2C_TRANSFER_POLLING); uint8_t keypad_row = data_in ^ 0xFF; } |
||||||||||||||||||||||||
| ADC (Analogue to Digital Converter) | |||||||||||||||||||||||||
| Uses: |
|
||||||||||||||||||||||||
| Notes: |
|
||||||||||||||||||||||||
| Pin Functions | |||||||||||||||||||||||||
| AD0.x | Analogue to Digital input/channel x | ||||||||||||||||||||||||
| Code | |||||||||||||||||||||||||
| Important headers: |
|
||||||||||||||||||||||||
| Device struct defines: |
|
||||||||||||||||||||||||
| Interrupt defines: |
|
||||||||||||||||||||||||
| Example code: |
#include "LPC17xx.h" #include "lpc_types.h" #include "lpc17xx_pinsel.h" #include "lpc17xx_adc.h" void main (void) { // Set up the pin configuration struct for using analogue in on mbed pin 16. PINSEL_CFG_Type PinCfg; PinCfg.Funcnum = PINSEL_FUNC_1; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Portnum = PINSEL_PORT_0; PinCfg.Pinnum = PINSEL_PIN_24; // Configure mbed pin 16 to use the analogue in channel 1 function (AD0.1). PINSEL_ConfigPin(&PinCfg); // Set up the ADC sampling at 200kHz (maximum rate). ADC_Init(LPC_ADC, 200000); // Enable ADC channel 1. ADC_ChannelCmd(LPC_ADC, ADC_CHANNEL_1, ENABLE); // Set ADC to continuously sample. ADC_StartCmd (LPC_ADC, ADC_START_CONTINUOUS); // Set ADC to start converting. ADC_BurstCmd (LPC_ADC, ENABLE); // Enable interrupts for ADC conversion completing. NVIC_EnableIRQ(ADC_IRQn); // Enable interrupts globally. __enable_irq(); } // The ADC interrupt handler, gets called every time an A to D conversion completes. void ADC_IRQHandler (void) { // Get the value read on ADC channel 1. uint16_t analogue_value = ADC_ChannelGetData(LPC_ADC, ADC_CHANNEL_1); /* Now do something with the read analogue value. */ } |
||||||||||||||||||||||||
| DAC (Digital to Analogue Converter) | |||||||||||||||||||||||||
| Uses: |
|
||||||||||||||||||||||||
| Notes: |
|
||||||||||||||||||||||||
| Pin Functions | |||||||||||||||||||||||||
| AOUT | Analogue OUTput | ||||||||||||||||||||||||
| Code | |||||||||||||||||||||||||
| Important headers: |
|
||||||||||||||||||||||||
| Device struct defines: |
|
||||||||||||||||||||||||
| Useful functions: |
|
||||||||||||||||||||||||
| Example code: |
#include "LPC17xx.h" #include "lpc_types.h" #include "lpc17xx_pinsel.h" #include "lpc17xx_dac.h" void main (void) { // Set up the pin configuration struct for using analogue out on mbed pin 18. PINSEL_CFG_Type PinCfg; PinCfg.Funcnum = PINSEL_FUNC_2; PinCfg.OpenDrain = PINSEL_PINMODE_NORMAL; PinCfg.Pinmode = PINSEL_PINMODE_PULLUP; PinCfg.Portnum = PINSEL_PORT_0; PinCfg.Pinnum = PINSEL_PIN_26; // Configure mbed pin 18 to use the analogue out function. PINSEL_ConfigPin(&PinCfg); // Initialise the DAC so it is ready to use. DAC_Init(LPC_DAC); // Set DAC output to half (approx. 1.65v). DAC_UpdateValue (512); /* wait for at least * 1 us then do * more updates */ } |
||||||||||||||||||||||||
| UART (Universal Asynchronous Receiver/Transmitter) | |||||||||||||||||||||||||
| Uses: |
|
||||||||||||||||||||||||
| Notes: |
|
||||||||||||||||||||||||
| Pin Functions | |||||||||||||||||||||||||
| TXDx | Serial Output for UART device x | ||||||||||||||||||||||||
| RXDx | Serial Input for UART device x | ||||||||||||||||||||||||
| Code | |||||||||||||||||||||||||
| Important headers: |
|
||||||||||||||||||||||||
| Device struct defines: |
|
||||||||||||||||||||||||
| Interrupt defines: |
|
||||||||||||||||||||||||
| PWM (Pulse Width Modulation) | |||||||||||||||||||||||||
| Uses: |
|
||||||||||||||||||||||||
| Pin Functions | |||||||||||||||||||||||||
| PWM1.x | Pulse Width Modulation output x | ||||||||||||||||||||||||
| Code | |||||||||||||||||||||||||
| Important headers: |
|
||||||||||||||||||||||||
| Device struct defines: |
|
||||||||||||||||||||||||
| Interrupt defines: |
|
||||||||||||||||||||||||
| CAN (Controller Area Network) | |||||||||||||||||||||||||
| Uses: |
|
||||||||||||||||||||||||
| Notes: |
|
||||||||||||||||||||||||
| Pin Functions | |||||||||||||||||||||||||
| RDx | Receive Data? x | ||||||||||||||||||||||||
| TDx | Transmit Data? x | ||||||||||||||||||||||||
| Code | |||||||||||||||||||||||||
| Important headers: |
|
||||||||||||||||||||||||
| Device struct defines: |
|
||||||||||||||||||||||||
| Interrupt defines: |
|
||||||||||||||||||||||||
| Using LPC17xx interrupts |
|---|
|