1.1.8.4.12 DRV_SPI_WriteTransfer Function
C
void DRV_SPI_WriteTransfer ( const DRV_HANDLE handle, void* pTransmitData, size_t txSize );
Summary
This is a blocking function that transmits data over SPI.
Description
This function does a blocking write operation. The function blocks till the data transmit is complete. Function will return true if the transmit is successful or false in case of an error. The failure will occur for the following reasons:
if the handle is invalid
if the pointer to the transmit buffer is NULL
if the transmit size is 0
Precondition
DRV_SPI_Open must have been called to obtain a valid opened device handle.
DRV_SPI_TransferSetup must have been called if GPIO pin has to be used for
chip select or any of the setup parameters has to be changed dynamically.
Parameters
Param | Description |
---|---|
handle | Handle of the communication channel as returned by the DRV_SPI_Open function. |
*pTransmitData | Pointer to the data which has to be transmitted. |
txSize | Number of bytes to be transmitted. The size must be specified in terms of the SPI data width. For example, if the data width is 8-bits, and if 10 bytes are being transmitted, then the txSize must be set to 10. If the data width is 16-bits then transmitting 10 bytes requires specifying the txSize as 10 (meaning 10 16-bit words). |
Returns
true - transfer is successful
false - error has occurred
Example
MY_APP_OBJ myAppObj; uint8_t myTxBuffer[MY_TX_BUFFER_SIZE]; // mySPIHandle is the handle returned by the DRV_SPI_Open function. if (DRV_SPI_WriteTransfer(mySPIhandle, myTxBuffer, MY_TX_BUFFER_SIZE) == false) { // Handle error here }
Remarks
This function is thread safe in a RTOS application.
This function should not be called from an interrupt context.