USER MANUAL RC188x-GPR
2019 Radiocrafts AS
RIIM User Manual (rev.1.2)
Page
19
of
23
8.11. SPI
The SPI module has all the functions needed for accessing the SPI bus. For chip select control, the user must use
a GPIO. For all data transfer and initialization, the SPI module can be used. In the example below, usage of both
GPIO and SPI is demonstrated. Only 4-wire SPI is supported
The following example shows how to set up SPI and access the ST LIS3DE accelerometer:
Example : ICI code
RIIM_SETUP
()
{
// Set up GPIO. We must use one GPIO for SPI chip select
GPIO
.
setDirection
(
GPIO_3
,
OUTPUT
);
GPIO
.
setValue
(
GPIO_3
,
HIGH
);
// Set up interface towards the LIS3DE-sensor
SPI
.
init
(
4000000
,
SPI_POL_0_PHA_0
);
// Setup accelerometer to update every second
uint8_t
wbuf
[
2
];
wbuf
[
0
]=
0x20
;
// 0 (write), 0(do not increment), 0x20 (register address)
wbuf
[
1
]=
0x17
;
// 1 Hz, enable X,Y and Z axes
GPIO
.
setValue
(
GPIO_3
,
LOW
);
SPI
.
transfer
(
2
,
wbuf
,
NULL
);
GPIO
.
setValue
(
GPIO_3
,
HIGH
);
return
UAPI_OK
;
}
Example 11 - SPI example code
The following functions are part of the SPI module:
Function
Description
init
(Speed, SPIClockMode)
Initialize the SPI module. Speed and SPI mode must be specified
transfer
(Count, txBuffer, rxBuffer)
Transfer bytes over the SPI bus. Reading bytes is implicit, but any of
the buffers can be set to
NULL
to disable reading or writing (disable
writing means putting zero on the MOSI line)
Table 11 - SPI functions