| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
LPC17xx/40xx SPI example
Peripheral examples

## Detailed Description

Example description
This example describes how to use the on-chip SPI peripheral in POLLING and INTERRUPT mode. The on-chip SSP1 peripheral is also used as the SPI partner. When SPI peripheral is configured as mater, the SSP1 will be slave and vice versa.

     SPI configuration:<br>
         - CPHA = 0: data is sampled on the first clock edge of SCK.<br>
         - CPOL = 0: SCK is active high.<br>
         - Sample rate = 400kHz.<br>
         - DSS = 8: 8 bits per transfer.<br>

After initialize transmit buffer, SPI master/slave will transfer a number of bytes to SPI slave/master and receive data concurrently.
After the transfer completed, receive and transmit buffer will be compared. If they are matching, the on-board LED is ON.
This example supports 2 transfer modes: POLLING mode and INTERRUPT mode . In case the SPI peripheral is configued as slave, only interrupt mode can be selected.

Special connection requirements
How to run: hardware configuration
-NXP LPC1769 Xpresso board

- SPI connection:
- P0.15: SPI_SCK (J6.13)
- P0.16 : SPI_SSEL (J6.14)
- P0.17: SPI_MISO (J6.12)
- P0.18: SPI_MOSI (J6.11)
- SSP1 connection:
- P0.7: SSP1_SCK (J6.7)
- P0.6: SSP1_SSEL (J6.8)
- P0.8: SSP1_MISO (J6.6)
- P0.9: SSP1_MOSI (J6.5)
  The SCK pin of SPI is connected to SCK of SSP1.
  The SSEL pin of SPI is connected to SSEL of SSP1.
  The MISO pin of SPI is connected to MISO of SSP1.
  The MOSI pin of SPI is connected to MOSI of SSP1.

Build procedures:
LPC17xx/40xx example quickstart for Keil uVision4
LPC17xx/40xx example quickstart for IAR EWARM
LPC17xx/40xx example quickstart for Code Red Xpresso

Supported boards and board setup:
NXP Xpresso LPC1769 board

Submitting LPCOpen issues:
Community support for LPCOpen

## Macros
#define | BUFFER_SIZE (0x100)
#define | SPI_MASTER_MODE_SEL (0x31)
#define | SPI_SLAVE_MODE_SEL (0x32)
#define | SPI_MODE_SEL (SPI_MASTER_MODE_SEL)
#define | SPI_POLLING_SEL (0x31)
#define | SPI_INTERRUPT_SEL (0x32)
#define | SPI_TRANSFER_MODE_SEL (SPI_POLLING_SEL)
#define | LPC_SSP LPC_SSP1
#define | LPC_GPDMA_SSP_TX GPDMA_CONN_SSP1_Tx
#define | LPC_GPDMA_SSP_RX GPDMA_CONN_SSP1_Rx

## Functions
static void | bufferInit (uint8_t *tx_buf, uint8_t *rx_buf)
static uint8_t | bufferVerify (uint8_t *tx_buf, uint8_t *rx_buf)
void | DMA_IRQHandler (void)
| DMA interrupt handler sub-routine. Set the waiting flag when transfer is successful.
static void | appSSPRun (void)
static void | appSPIRun (void)
int | main (void)
| Main routine for SPI example.

## Variables
static uint8_t | spi_tx_buf [BUFFER_SIZE]
static uint8_t | spi_rx_buf [BUFFER_SIZE]
static CHIP_SPI_CONFIG_FORMAT_T | spi_format
static CHIP_SPI_DATA_SETUP_T | spi_xf
static volatile uint8_t | spi_xfer_completed = 0
static uint8_t | ssp_tx_buf [BUFFER_SIZE]
static uint8_t | ssp_rx_buf [BUFFER_SIZE]
static SSP_ConfigFormat | ssp_format
static uint8_t | ssp_dma_tx_ch
static uint8_t | ssp_dma_rx_ch
static volatile uint8_t | ssp_dma_txf_completed = 0
static volatile uint8_t | ssp_dma_rxf_completed = 0

## Macro Definition Documentation

#define BUFFER_SIZE (0x100)

Definition at line 89 of file spi.c.

#define LPC_GPDMA_SSP_RX GPDMA_CONN_SSP1_Rx

Definition at line 105 of file spi.c.

#define LPC_GPDMA_SSP_TX GPDMA_CONN_SSP1_Tx

Definition at line 104 of file spi.c.

#define LPC_SSP LPC_SSP1

Definition at line 103 of file spi.c.

#define SPI_INTERRUPT_SEL (0x32)

Definition at line 96 of file spi.c.

#define SPI_MASTER_MODE_SEL (0x31)

Definition at line 91 of file spi.c.

#define SPI_MODE_SEL (SPI_MASTER_MODE_SEL)

Definition at line 93 of file spi.c.

#define SPI_POLLING_SEL (0x31)

Definition at line 95 of file spi.c.

#define SPI_SLAVE_MODE_SEL (0x32)

Definition at line 92 of file spi.c.

#define SPI_TRANSFER_MODE_SEL (SPI_POLLING_SEL)

Definition at line 100 of file spi.c.

## Function Documentation

static void appSPIRun | ( | void |  | ) |
| static

Definition at line 189 of file spi.c.

static void appSSPRun | ( | void |  | ) |
| static

Definition at line 167 of file spi.c.

static void bufferInit | ( | uint8_t * | tx_buf,
|  | uint8_t * | rx_buf
| ) |  |
| static

Definition at line 129 of file spi.c.

static uint8_t bufferVerify | ( | uint8_t * | tx_buf,
|  | uint8_t * | rx_buf
| ) |  |
| static

Definition at line 141 of file spi.c.

void DMA_IRQHandler | ( | void |  | ) |

DMA interrupt handler sub-routine. Set the waiting flag when transfer is successful.

Returns
  Nothing

Definition at line 156 of file spi.c.

int main | ( | void |  | ) |

Main routine for SPI example.

Main program body.

Returns
  Nothing

Definition at line 235 of file spi.c.

## Variable Documentation

CHIP_SPI_CONFIG_FORMAT_T spi_format
| static

Definition at line 109 of file spi.c.

uint8_t spi_rx_buf[BUFFER_SIZE]
| static

Definition at line 108 of file spi.c.

uint8_t spi_tx_buf[BUFFER_SIZE]
| static

Definition at line 107 of file spi.c.

CHIP_SPI_DATA_SETUP_T spi_xf
| static

Definition at line 110 of file spi.c.

volatile uint8_t spi_xfer_completed = 0
| static

Definition at line 111 of file spi.c.

uint8_t ssp_dma_rx_ch
| static

Definition at line 116 of file spi.c.

volatile uint8_t ssp_dma_rxf_completed = 0
| static

Definition at line 118 of file spi.c.

uint8_t ssp_dma_tx_ch
| static

Definition at line 116 of file spi.c.

volatile uint8_t ssp_dma_txf_completed = 0
| static

Definition at line 117 of file spi.c.

SSP_ConfigFormat ssp_format
| static

Definition at line 115 of file spi.c.

uint8_t ssp_rx_buf[BUFFER_SIZE]
| static

Definition at line 114 of file spi.c.

uint8_t ssp_tx_buf[BUFFER_SIZE]
| static

Definition at line 113 of file spi.c.