1.30.18.42 SERCOMx_SPI_ReadCountGet Function

C

/* x = SERCOM instance number */

/* SPI slave mode */

size_t SERCOMx_SPI_ReadCountGet(void)

Summary

Returns the number of bytes pending to be read out from the PLIB's internal receive buffer

Description

This function returns the number of unread bytes availabe in the SPI slave PLIB's internal receive buffer. Application can call this API to know the bytes available in PLIBs internal buffer before calling the SERCOMx_SPI_Read API.

Precondition

The SERCOMx_SPI_Initialize function must have been called

Parameters

None

Returns

size_t - Number of bytes available in the PLIB's internal receive buffer

Example

uint8_t APP_RxData[10];
size_t nBytesAvailable;
size_t nBytesRead;

void SPIEventHandler(uintptr_t context )
{
    if (SERCOM0_SPI_ErrorGet() == SPI_SLAVE_ERROR_NONE)
    {
        nBytesAvailable = SERCOM0_SPI_ReadCountGet();
        
        nBytesRead = SERCOM0_SPI_Read(APP_RxData, nBytesAvailable);
    }
    else
    {
        // Handle error
    }
    
}

SERCOM0_SPI_CallbackRegister(SPIEventHandler, (uintptr_t) 0);

Remarks

None.