1.35.21.40 USARTx_SPI_CallbackRegister Function

C

/* x = USART SPI instance number */

/* USART SPI master (non-blocking mode) mode */

void USARTx_SPI_CallbackRegister(USART_SPI_CALLBACK callback, uintptr_t context )

Summary

This function allows application to register a callback function for the PLIB to call back when the requested data transfer operation has completed.

Description

This function sets the pointer to a client/application function to be called "back" when the given USARTx_SPI's transfer events occur. It also passes a context value (usually a pointer to a context structure) that is passed into the function when it is called. The specified callback function will be called from the peripheral interrupt context. The callback should be registered before a transfer operation is requested.

Precondition

The USARTx_SPI_Initialize function must have been called. This function is only available if the library is configured for interrupt operation mode.

Parameters

Param Description
callback A pointer to a function with a calling signature defined by the USART_SPI_CALLBACK data type. Setting this to NULL disables the callback feature.
context A value (usually a pointer) which is passed (unused) into the function identified by the callback parameter

Returns

None.

Example

  • USART SPI master (non-blocking mode) mode*

uint8_t txBuffer[4];
uint8_t rxBuffer[10];
size_t txSize = 4;
size_t rxSize = 10;
bool reqAccepted;

void APP_USART1_SPITransferHandler(uintptr_t context)
{
    //Transfer was completed without error, do something else now.
}

USART1_SPI_Initialize();
USART1_SPI_CallbackRegister(&APP_USART1_SPITransferHandler, (uintptr_t)NULL);
if(USART1_SPI_WriteRead(&txBuffer, txSize, &rxBuffer, rxSize))
{
    // request got accepted
}
else
{
    // request didn't get accepted, try again later with correct arguments
}

Remarks

None