| Raspberry Pi CM5 IoT In C - Getting Started With SPI |
| Written by Harry Fairhead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Monday, 29 December 2025 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Page 1 of 4 The CM5 has SPI and you can use it via Linux drivers or directly. In this article we look at how to use it via a driver. This is an extract from the newly-published Raspberry Pi Compute Module 5 IoT In C Raspberry Pi Compute Module 5
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
SPI0 GPIO Mode 0 | ||
|---|---|---|
|
Function |
Pin |
GPIO |
|
MOSI |
19 |
GPIO10 |
|
MISO |
21 |
GPIO09 |
|
SCLK |
23 |
GPIO11 |
|
CE0 |
24 |
GPIO08 |
|
CE1 |
26 |
GPIO07 |
|
CE2 |
5 |
GPIO03 |
|
CE3 |
7 |
GPIO04 |
|
SPI1 GPIO Mode 0 | ||
|---|---|---|
|
Function |
Pin |
GPIO |
|
MOSI |
38 |
GPIO20 |
|
MISO |
35 |
GPIO19 |
|
SCLK |
40 |
GPIO21 |
|
CE0 |
12 |
GPIO18 |
|
CE1 |
11 |
GPIO17 |
|
CE2 |
36 |
GPIO16 |
|
CE3 |
13 |
GPIO27 (mode 8) |
|
SPI2 GPIO Mode 8 |
||
|
Function |
Pin |
GPIO |
|
MOSI |
3 |
GPIO02 |
|
MISO |
28 |
GPIO01 |
|
SCLK |
5 |
GPIO03 |
|
CE0 |
27 |
GPIO00 |
|
CE1 |
18 |
GPIO24 |
|
SPI3 GPIO Mode 8 |
||
|
Function |
Pin |
GPIO |
|
MOSI |
3 |
GPIO02 |
|
MISO |
28 |
GPIO01 |
|
SCLK |
5 |
GPIO03 |
|
CE0 |
27 |
GPIO00 |
|
CE1 |
22 |
GPIO25 |
|
SPI4 GPIO Mode 8 |
||
|
Function |
Pin |
GPIO |
|
MOSI |
19 |
GPIO10 |
|
MISO |
21 |
GPIO09 |
|
SCLK |
23 |
GPIO11 |
|
CE0 |
24 |
GPIO08 |
|
SPI5 GPIO Mode 8 |
||
|
Function |
Pin |
GPIO |
|
MOSI |
8 |
GPIO14 |
|
MISO |
33 |
GPIO13 |
|
SCLK |
10 |
GPIO15 |
|
CE0 |
32 |
GPIO12 |
|
CE1 |
37 |
GPIO26 |
Notice that some SPI controllers share GPIO lines and therefore cannot be used at the same time, e.g SPI2 and SPI3, SPI4 and SPI0. For these and other reasons it is better to use SPI0 and SPI1 if at all possible.
