Jump to main content

##

# 2.66.9 MCSPIx_ReadCountGet Function

## C

    /* x = MCSPI instance number */

    /* MCSPI slave mode */
    size_t MCSPIx_ReadCountGet(void)

## Summary

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

## Description

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

## Precondition

The MCSPIx_Initialize function must have been called.

## Parameters

None

## Returns

size_t - Number of bytes available in the PLIB's internal receive buffer. If 16/32 bit modes are supported, the return value is specified in terms of 16/32 bit words.

## Example

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

    void MCSPIEventHandler(uintptr_t context )
    {
        if (MCSPI1_ErrorGet() == MCSPI_SLAVE_ERROR_NONE)
        {
            nBytesAvailable = MCSPI1_ReadCountGet();

            nBytesRead = MCSPI1_Read(APP_RxData, nBytesAvailable);
        }
        else
        {
            // Handle error
        }

    }

    MCSPI1_CallbackRegister(MCSPIEventHandler, (uintptr_t) 0);

## Remarks

None.