pic32/libraries/DSPI/DSPI.cpp
/* ------------------------------------------------------------ */
/***	DSPI::transfer
**
**	Parameters:
**		cbReq	- number of bytes to receive from the slave
**		bPad	- pad byte to send to slave
**		pbRcv	- buffer to hold received bytes
**
**	Return Value:
**		none
**
**	Errors:
**		none
**
**	Description:
**		This function will receive the specified number of bytes
**		from the slave. The given pad byte will be sent to the
**		slave to cause the received bytes to be sent.
*/
:transfer

cbReq   - number of bytes to receive from the slave
bPad    - pad byte to send to slave
pbRcv   - buffer to hold received bytes

Return Value:
none

none

This function will receive the specified number of bytes
from the slave. The given pad byte will be sent to the
slave to cause the received bytes to be sent.
: transfer cbReq - number of bytes to receive from the slave bPad - pad byte to send to slave pbRcv - buffer to hold received bytes Return Value : none none This function will receive the specified number of bytes from the slave . The given pad byte will be sent to the slave to cause the received bytes to be sent .
void
DSPI::transfer(uint16_t cbReq, uint8_t bPad, uint8_t * pbRcv) {
#ifdef ENH_BUFFER
    pspi->sxCon.set = 1<<ENH_BUFFER;
    uint16_t toWrite = cbReq;
    uint16_t toRead = cbReq;
    uint16_t rPos = 0;
    pspi->sxCon.clr = 1<<_SPICON_MODE32 | 1<<_SPICON_MODE16;
    while (toWrite > 0 || toRead > 0) {
        if (toWrite > 0) {
            if ((pspi->sxStat.reg & (1<<_SPISTAT_SPITBF)) == 0) {
                pspi->sxBuf.reg = bPad;
                toWrite--;
            }
        }
        if (toRead > 0) {
            if ((pspi->sxStat.reg & (1<<_SPISTAT_SPIRBE)) == 0) {
                pbRcv[rPos++] = pspi->sxBuf.reg;
                toRead--;
            }
        }
    }
    pspi->sxCon.clr = 1<<ENH_BUFFER;
#else
    for (cbCur = cbReq; cbCur > 0; cbCur--) {
        *pbRcv++ = transfer(bPad);
    }
#endif
}
void DSPI :: transfer ( uint16_t cbReq , uint8_t bPad , uint8_t * pbRcv ) { #ifdef ENH_BUFFER pspi -> sxCon . set = 1 << ENH_BUFFER ; uint16_t toWrite = cbReq ; uint16_t toRead = cbReq ; uint16_t rPos = 0 ; pspi -> sxCon . clr = 1 << _SPICON_MODE32 | 1 << _SPICON_MODE16 ; while ( toWrite > 0 || toRead > 0 ) { if ( toWrite > 0 ) { if ( ( pspi -> sxStat . reg & ( 1 << _SPISTAT_SPITBF ) ) == 0 ) { pspi -> sxBuf . reg = bPad ; toWrite -- ; } } if ( toRead > 0 ) { if ( ( pspi -> sxStat . reg & ( 1 << _SPISTAT_SPIRBE ) ) == 0 ) { pbRcv [ rPos ++ ] = pspi -> sxBuf . reg ; toRead -- ; } } } pspi -> sxCon . clr = 1 << ENH_BUFFER ; #else for ( cbCur = cbReq ; cbCur > 0 ; cbCur -- ) { * pbRcv ++ = transfer ( bPad ) ; } #endif }
DSPI::transfer
DSPI :: transfer