1.8.10.13 MCSPIx_Ready Function

C

/* x = MCSPI instance number */

/* MCSPI slave mode */
void MCSPIx_Ready(void)

Summary

Drives the MCSPI slave busy line to ready (not busy) state

Description

This function drives the MCSPI slave busy line to ready state. The slave busy line is driven to active state (busy) when the chip select is driven active by the MCSPI master. When the data transfer is complete, the chip select is driven inactive and a callback is given to the application. The application can parse the received data and prepare a response for the MCSPI master. Once the response is ready, the MCSPI slave can release the busy line by calling this API which drives the busy line to inactive state (not busy). All this while the MCSPI master must wait for the busy line to become inactive (not busy) before initiating a new transfer with the MCSPI slave.

Precondition

The MCSPIx_Initialize() should have been called.

Parameters

None

Returns

None

Example

uint8_t APP_TxData[10];
size_t nBytesRead;

void MCSPIEventHandler(uintptr_t context )
{
    if (MCSPI1_ErrorGet() == MCSPI_SLAVE_ERROR_NONE)
    {
        nBytesRead = MCSPI1_Read(APP_RxData, MCSPI1_ReadCountGet());
        
        switch(APP_RxData[0])
        {
            case APP_CMD_WRITE:
            // MCSPI master is writing data to MCSPI slave
            // Keep the busy line asserted until the write operation is complete
            // Busy line will be de-asserted later when the write operation is complete
            appData.status.busy = 1;
            
            // Change the state to perform write operation
            state = APP_STATE_WRITE;
            
            break;
            
            case APP_CMD_READ:
            
            // MCSPI master is reading data from MCSPI slave
            // Provide the requested data and drive the busy line inactive
            MCSPI1_Write(APP_TxData, 10);
            break;
        }
        
        if (appData.status.busy == 0)
        {
            // Indicate to MCSPI Master that slave is ready for data transfer
            // This if condition will be executed for the APP_CMD_READ case.
            MCSPI1_Ready();
        }
    }
}

Remarks

This API is available only if the Busy signal feature is enabled in MCC.