Low Power Serial Peripheral Interface (LPSPI)

Detailed Description

Low Power Serial Peripheral Interface (LPSPI) Peripheral Driver.

The LPSPI driver allows communication on an SPI bus using the LPSPI module in the S32K1xx processors.

Features

How to integrate LPSPI in your application

In order to use the LPSPI driver it must be first initialized in either master or slave mode, using functions LPSPI_DRV_MasterInit() or LPSPI_DRV_SlaveInit(). Once initialized, it cannot be initialized again for the same LPSPI module instance until it is de-initialized, using LPSPI_DRV_MasterDeinit() or LPSPI_DRV_SlaveDeinit(). Different LPSPI module instances can function independently of each other.

In each mode (master/slave) are available two types of transfers: blocking and non-blocking. The functions which initiate blocking transfers will configure the time out for transmission. If time expires LPSPI_MasterTransferBlocking/LPSPI_SlaveTransferBlocking will return error and the transmission will be aborted.

Depending on frame size receive and transmit buffers must be aligned as is presented in the next table:

Bits/frameless or equal with 8 between 9 and 16 more than 16
Alignment 1 byte 2 bytes 4 bytes

This alignment requirements should be taken into consideration when "transferByteCount" is configured. For a better understanding these are some examples of how to calculate the right value to "transferByteCount":

Bits/framenumber of frames bytes per frame transferByteCount
8 10 1 10
10 10 2 20
24 10 4 40
32 10 4 40
40 10 8 80
64 10 8 80

Important Notes

Example code

const lpspi_master_config_t Send_MasterConfig0 = {
.bitsPerSec = 50000U,
.whichPcs = LPSPI_PCS0,
.pcsPolarity = LPSPI_ACTIVE_HIGH,
.isPcsContinuous = false,
.bitcount = 8U,
.lpspiSrcClk = 8000000U,
.clkPolarity = LPSPI_SCK_ACTIVE_HIGH,
.lsbFirst = false,
.transferType = LPSPI_USING_INTERRUPTS,
};
const lpspi_slave_config_t Receive_SlaveConfig0 = {
.bitcount = 8U,
.whichPcs = LPSPI_PCS0,
.clkPolarity = LPSPI_SCK_ACTIVE_HIGH,
.lsbFirst = false,
.transferType = LPSPI_USING_INTERRUPTS,
};
/* Initialize clock and pins */
LPSPI_DRV_MasterInit(0U, &masterState, &Send_MasterConfig0);
/* Set delay between transfer, PCStoSCK and SCKtoPCS to 10 microseconds. */
LPSPI_DRV_MasterSetDelay(0U, 10U, 10U, 10u);
/* Initialize LPSPI1 (Slave)*/
LPSPI_DRV_SlaveInit(1U, &slaveState, &Receive_SlaveConfig0);
/* Allocate memory */
masterDataSend = (uint8_t*)calloc(100, sizeof(uint8_t));
masterDataReceive = (uint8_t*)calloc(100, sizeof(uint8_t));
slaveDataSend = (uint8_t*)calloc(100, sizeof(uint8_t));
slaveDataReceive = (uint8_t*)calloc(100, sizeof(uint8_t));
bufferSize = 100U;
testStatus[0] = true;
LPSPI_DRV_SlaveTransfer(0U, slaveDataSend,
slaveDataReceive, bufferSize);
LPSPI_DRV_MasterTransferBlocking(1U, &Send_MasterConfig0, masterDataSend,
masterDataReceive, bufferSize, TIMEOUT);

Modules

 LPSPI Driver
 Low Power Serial Peripheral Interface Peripheral Driver.