User manual

LPCXpresso Experiment Kit - User’s Guide
Page 79
Copyright 2013 © Embedded Artists AB
There is no specific upper frequency for the SCLK frequency. It depends on the SPI peripheral block in
the microcontroller, the external SPI slave chip(s) and how far away the master and slaves(s) is/are.
For breadboard experiments, the SCLK frequency should typically not exceed 1MHz. With proper pcb
layout a frequency up to 20-30 MHz should not be a problem (assuming the chips involved support this
frequency).
For more information about SPI, see http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus.
There are some so called decoupling capacitors that are not shown on the breadboard setups.
Decoupling capacitors are added to reduce voltage dips on the supply voltage to integrated circuits. In
the LPCXpresso Experiment Kit, decoupling capacitors are used on five different locations in the
schematic; U3/C7, U4/C8, U5/C9, U6/C10, U7/C11. A standard value of 100nF has been selected for
the capacitor.
When working on breadboard signal frequencies cannot be too high. A good rule of thumb is to keep
signal frequencies below 1MHz. A breadboard is simply not a good place for high frequency
electronics. The decoupling capacitors can typically be ignored on the breadboard. When soldering the
components to the pcb it is however recommended to also solder the decoupling capacitors.
Have a look in chapter 14 - LPC111x/LPC11Cxx SPI0/1 with SSP in the LPC111x user’s manual for a
description of how the SSP block works. SSP (Synchronous Serial Port) is NXP’s peripheral block that
is capable of SPI communication (plus some other formats that will not be investigated in this
experiment). It is SSP#0 that we will work with, with the following pinning:
GPIO_1-MOSI (PIO0_9)
GPIO_2-MISO (PIO0_8)
GPIO_3-SCK (PIO2_11)
Further, we will use GPIO signals for SSEL. More specifically signals GPIO_4-LED-SSEL (PIO0_2) for
the shift register experiments and GPIO_8-LED-SSEL (PIO2_0) for the e2prom experiment. It is
possible to use the SSP#0 SSEL signal directly, which is available on PIO0_2, but in order to make the
code general and supporting multiple SPI slaves we will control the SSEL signals with GPIO signals.
The code below initializes the SPI interface. Study the code below and read the LPC111x user’s
manual to understand the different register initialization steps. Especially note that in order to receive
one byte, one byte has to be transmitted (i.e., one byte is “clocked out”, one is “clocked in” at the same
time).
#define FIFOSIZE 8
/* SSP Status register */
#define SSPSR_TFE (1 << 0)
#define SSPSR_TNF (1 << 1)
#define SSPSR_RNE (1 << 2)
#define SSPSR_RFF (1 << 3)
#define SSPSR_BSY (1 << 4)
/* SSP CR0 register */
#define SSPCR0_DSS (1 << 0)
#define SSPCR0_FRF (1 << 4)
#define SSPCR0_SPO (1 << 6)
#define SSPCR0_SPH (1 << 7)
#define SSPCR0_SCR (1 << 8)
/* SSP CR1 register */
#define SSPCR1_LBM (1 << 0)
#define SSPCR1_SSE (1 << 1)
#define SSPCR1_MS (1 << 2)
#define SSPCR1_SOD (1 << 3)