| 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
LPC11xx SSP/SPI example
Peripheral examples

## Detailed Description

Example description
This example describes how to use SPI in POLLING or INTERRUPT mode.
The LOOPBACK_TEST macro is used to enable Loop-back mode of SPI peripheral. It allows a simple software testing. The transmit and receive data is connected together. No more connection is required in this case. If LOOPBACK_TEST macro is disabled, it is needed to connect 2 hardware boards, one for Master and one for Slave. Use SSP_MODE_TEST macro to select the SPI mode.
SPI configuration:

- CPHA = 0: Data is sampled on the first clock edge of SCK.
- CPOL = 0: The rest state of the clock (between frames) is low.
- Sample rate = 100KHz.
- DSS = 8: 8 bits per transfer.
  After initialize transmit buffer, SPI master/slave will transfer a number of bytes to SPI slave/master and receive data concurrently.
  When transferring completed, receive and transmit buffer will be compared. If they match, the led is ON. If not the led is OFF.
  This example supports 2 transfer modes: POLLING mode and INTERRUPT mode.

Special connection requirements
Connects SPI pins of the master boards to the slave boards.

- LPCXpresso LPC11U14:
  - P0.6: SPI_SCK
  - P0.2: SPI_SSEL
  - P0.8: SPI_MISO
  - P0.9: SPI_MOSI
- LPCXpresso LPC11C24:
  - P2.11: SPI_SCK
  - P0.2: SPI_SSEL
  - P0.8: SPI_MISO
  - P0.9: SPI_MOSI
    The SCK pin of master board is connected to SCK of slave board.
    The SSEL pin of master board is connected to SSEL of slave board.
    The MISO pin of master board is connected to MISO of slave board.
    The MOSI pin of master board is connected to MOSI of slave board.
    Common ground must be connected together between two boards.

Build procedures:
LPC11xx example quickstart for Code Red Xpresso
LPC11xx example quickstart for Keil uVision4
LPC11xx example quickstart for IAR EWARM

Supported boards and board setup:
NXP Xpresso LPC11U14 board
NXP Xpresso LPC11C24 board

Submitting LPCOpen issues:
Community support for LPCOpen

## Macros
#define | LOOPBACK_TEST 1
#define | SSP_MODE_TEST 1 /*1: Master, 0: Slave */
#define | POLLING_MODE 1
#define | INTERRUPT_MODE 0
#define | BUFFER_SIZE (0x100)
#define | SSP_DATA_BITS (SSP_BITS_8)
#define | SSP_DATA_BIT_NUM(databits) (databits + 1)
#define | SSP_DATA_BYTES(databits) (((databits) > SSP_BITS_8) ? 2 : 1)
#define | SSP_LO_BYTE_MSK(databits)
#define | SSP_HI_BYTE_MSK(databits)
#define | LPC_SSP LPC_SSP0
#define | SSP_IRQ SSP0_IRQn
#define | SSPIRQHANDLER SSP0_IRQHandler

## Functions
static void | Buffer_Init (void)
static uint8_t | Buffer_Verify (void)
int | main (void)
| Main routine for SSP example.

## Variables
static uint8_t | Tx_Buf [BUFFER_SIZE]
static uint8_t | Rx_Buf [BUFFER_SIZE]
static SSP_ConfigFormat | ssp_format
static Chip_SSP_DATA_SETUP_T | xf_setup
static volatile uint8_t | isXferCompleted = 0

## Macro Definition Documentation

#define BUFFER_SIZE (0x100)

Definition at line 99 of file ssp.c.

#define INTERRUPT_MODE 0

Definition at line 95 of file ssp.c.

#define LOOPBACK_TEST 1

Definition at line 91 of file ssp.c.

#define LPC_SSP LPC_SSP0

Definition at line 107 of file ssp.c.

#define POLLING_MODE 1

Definition at line 93 of file ssp.c.

#define SSP_DATA_BIT_NUM | ( |  | databits | ) | (databits + 1)

Definition at line 101 of file ssp.c.

#define SSP_DATA_BITS (SSP_BITS_8)

Definition at line 100 of file ssp.c.

#define SSP_DATA_BYTES | ( |  | databits | ) | (((databits) > SSP_BITS_8) ? 2 : 1)

Definition at line 102 of file ssp.c.

#define SSP_HI_BYTE_MSK | ( |  | databits | ) |

Value:
((SSP_DATA_BYTES(databits) > 1) ? (0xFF >> \
(16 - SSP_DATA_BIT_NUM(databits))) : 0)

Definition at line 105 of file ssp.c.

#define SSP_IRQ SSP0_IRQn

Definition at line 108 of file ssp.c.

#define SSP_LO_BYTE_MSK | ( |  | databits | ) |

Value:
((SSP_DATA_BYTES(databits) > 1) ? 0xFF : (0xFF >> \
(8 - SSP_DATA_BIT_NUM(databits))))

Definition at line 103 of file ssp.c.

#define SSP_MODE_TEST 1 /*1: Master, 0: Slave */

Definition at line 92 of file ssp.c.

#define SSPIRQHANDLER SSP0_IRQHandler

Definition at line 109 of file ssp.c.

## Function Documentation

static void Buffer_Init | ( | void |  | ) |
| static

Definition at line 130 of file ssp.c.

static uint8_t Buffer_Verify | ( | void |  | ) |
| static

Definition at line 142 of file ssp.c.

int main | ( | void |  | ) |

Main routine for SSP example.

Main program body.

Returns
  Nothing

defined(CHIP_LPC175X_6X)

Definition at line 202 of file ssp.c.

## Variable Documentation

volatile uint8_t isXferCompleted = 0
| static

Definition at line 119 of file ssp.c.

uint8_t Rx_Buf[BUFFER_SIZE]
| static

Definition at line 115 of file ssp.c.

SSP_ConfigFormat ssp_format
| static

Definition at line 117 of file ssp.c.

uint8_t Tx_Buf[BUFFER_SIZE]
| static

Definition at line 112 of file ssp.c.

Chip_SSP_DATA_SETUP_T xf_setup
| static

Definition at line 118 of file ssp.c.