4.16 Serial Peripheral Interface (SPI)
1 Intro
2
Electrocardiogram (
Ecg
) Signals
The Electrocardiogram (
Ecg
)
•
Ecg
: electrical manifestation of heart activity recorded
from the body surface
•
monitoring of heart rate
The
Ecg
signal can be recorded fairly easily with surface
electrodes placed on the limbs and/or the chest, see pages
6
–
16
below.
Josef Goette
2
2009
4.16 Serial Peripheral Interface (SPI)
b
spi1
F
Writes data to SPI1 and SPI2 (polling)
b
spi2
F
Reads the values from the accelerometer MMA7455L over the SPI interface and writes
the data on the serial interface (polling).
b
spi3
F
spi2 realized with interrupts (IRQ).
STM32F103RB have 2 SPIs which are able to communicate up to 18 Mbits/s in slave and master
modes in fullduplex and simplex communication modes. The 3-bit prescaler gives 8 master mode
frequencies and the frame is configurable from 8-bit to 16-bit. The hardware CRC generation/ver-
ification supports basic SD Card/MMC modes.
4.16.1 Physical Layer
The synchronous serial interface SPI allows a data transfer in both directions. Therefore following
wires are required:
•
SCK: Clock (generated by the master)
•
MISO: Master in, Slave out
•
MOSI: Master out, Slave in
•
NPCK or NSS: Chip select for the slave, this wire is
not
generated by the SPI driver, a normal
GPIO pin has to be used.
In case more than one slave is accessed, an enable wire (NPCK or NSS) for each slave is required.
Figure
shows a basic SPI network.
4.16.2 Communication Protocol
The clock signal is only generated by the master device (normally the main microcontroller). If no
data are transmitted the clock is not active.
The data communication is shown in Figure
. The chip select line NSS goes low in order to
start the communication. This wire is needed since SPI don’t use an address like I
2
C.
The master sends its data on the MOSI line to the slave, the slave its data on the MISO line to the
master. Data are only allowed to change while a falling (CPOL = 0) or rising (CPOL = 1) flank of
SCK.
The SPI can as well be used as I
2
S bus for point to point communication. Refer to the reference
manual if you want to use this feature.
Lukas Kohler
45