void SPI1_Initialize (void)
{
// MSTEN Master; DISSDO disabled; PPRE 4:1; SPRE 4:1; MODE16 disabled; SMP Middle; DISSCK disabled; CKP Idle:Low, Active:High; CKE Active to Idle; SSEN disabled;
SPI1CON1 = 0x132;
// SPIFSD disabled; SPIBEN enabled; SPIFPOL disabled; SPIFE disabled; FRMEN disabled;
SPI1CON2 = 0x01;
// SPITBF disabled; SISEL SPI_INT_SPIRBF; SPIRBF disabled; SPIROV disabled; SPIEN enabled; SRXMPT disabled; SPISIDL disabled;
SPI1STAT = 0x800C;
}
void SPI1_Exchange( uint8_t *pTransmitData, uint8_t *pReceiveData )
{
while( SPI1STATbits.SPITBF == true )
{
}
SPI1BUF = *((uint8_t*)pTransmitData);
while ( SPI1STATbits.SRXMPT == true);
*((uint8_t*)pReceiveData) = SPI1BUF;
}
uint8_t SPI1_Exchange8bit( uint8_t data )
{
uint8_t receiveData;
SPI1_Exchange(&data, &receiveData);
return (receiveData);
}
|