Jump to main content

##

# 1.1.8.4.9 DRV_SPI_ReadTransferAdd Function

## C

    void DRV_SPI_ReadTransferAdd
    (
        const DRV_HANDLE handle,
        void* pReceiveData,
        size_t rxSize,
        DRV_SPI_TRANSFER_HANDLE * const transferHandle
    );

## Summary

Queues a read operation.

## Description

This function schedules a non-blocking read operation. The function returns with a valid transfer handle in the transferHandle argument if the request was scheduled successfully. The function adds the request to the instance specific software queue and returns immediately. While the request is in the queue, the application buffer is owned by the driver and should not be modified. This API will write rxSize bytes of dummy data and will read rxSize bytes of data in the memory location pointed by pReceiveData.

The function returns DRV_SPI_TRANSFER_HANDLE_INVALID in the transferHandle argument:

- if pReceiveData is NULL.
- if rxSize is zero.
- if the transfer handle is NULL.
- if the queue size is full or queue depth is insufficient.
- if the driver handle is invalid.

If the requesting client registered an event callback with the driver, the driver will issue a DRV_SPI_TRANSFER_EVENT_COMPLETE event if the transfer was processed successfully or DRV_SPI_TRANSFER_EVENT_ERROR event if the transfer was not processed successfully.

## 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.
*pReceiveData | Pointer to the location where received data has to be stored. It is user's responsibility to ensure pointed location has sufficient memory to store the read data.
rxSize | Number of bytes to be received. 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 received, then the rxSize must be set to 10. If the data width is 16-bits then receiving 10 bytes requires specifying the rxSize as 10 (meaning 10 16-bit words).
transferHandle | Handle which is returned by transfer add function.

## Returns

None.

## Example

    MY_APP_OBJ myAppObj;
    uint8_t myRxBuffer[MY_RX_BUFFER_SIZE];
    DRV_SPI_TRANSFER_HANDLE transferHandle;

    // mySPIHandle is the handle returned by the DRV_SPI_Open function.

    DRV_SPI_ReadTransferAdd(mySPIhandle, myRxBuffer, MY_RX_BUFFER_SIZE, &transferHandle);

    if(transferHandle == DRV_SPI_TRANSFER_HANDLE_INVALID)
    {
        // Error handling here
    }

    // Event is received when the transfer is processed.

## Remarks

- This function can be called from within the SPI Driver Transfer Event Handler that is registered by the client.
- It should not be called in the event handler associated with another SPI driver instance or event handler of any other peripheral.
- It should not be called directly in any ISR.