USER MANUAL RC188x-GPR2019 Radiocrafts AS RIIM User Manual (rev.1.2) Page 19 of 238.11. SPIThe SPI module has all the functions needed for accessing the SPI bus. For chip select control, the user must usea GPIO. For all data transfer and initialization, the SPI module can be used. In the example below, usage of bothGPIO and SPI is demonstrated. Only 4-wire SPI is supportedThe following example shows how to set up SPI and access the ST LIS3DE accelerometer:Example : ICI codeRIIM_SETUP(){// Set up GPIO. We must use one GPIO for SPI chip selectGPIO.setDirection(GPIO_3, OUTPUT);GPIO.setValue(GPIO_3, HIGH);// Set up interface towards the LIS3DE-sensorSPI.init(4000000,SPI_POL_0_PHA_0);// Setup accelerometer to update every seconduint8_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 axesGPIO.setValue(GPIO_3, LOW);SPI.transfer(2, wbuf, NULL);GPIO.setValue(GPIO_3, HIGH);return UAPI_OK;}Example 11 - SPI example codeThe following functions are part of the SPI module:Function Descriptioninit(Speed, SPIClockMode) Initialize the SPI module. Speed and SPI mode must be specifiedtransfer(Count, txBuffer, rxBuffer) Transfer bytes over the SPI bus. Reading bytes is implicit, but any ofthe buffers can be set to NULL to disable reading or writing (disablewriting means putting zero on the MOSI line)Table 11 - SPI functions