21.4.2.4 Receive Setup Procedure
To fully configure the module, the following must be known:
- TTICK (Equation 21-1)
- Number of Data Nibbles
- Hardware or Application Calculated CRC Validation
- Pause Period Present
Note: Application software can be used to implement an alternate CRC
algorithm. In these instances, disable hardware CRC checking by clearing CRCEN
(SENTxCON1[8]). The received CRC value (SENTxDAT[3:0]) can be read and compared against
the application calculated CRC value.
To initialize the module for Receive mode:
- Set RCVEN (SENTxCON1[11]) for Receive mode.
- Write the desired data frame length to NIBCNT[2:0] (SENTxCON1[2:0]).
- Set or clear CRCEN (SENTxCON1[8]) to configure the module for hardware or software CRC calculation.
- If the Pause period is present, set PPP (SENTxCON1[7]).
- Write the value of SYNCMAX (nominal Sync period + 20%) to SENTxCON2.
- Write the value of SYNCMIN (nominal Sync period – 20%) to SENTxCON3.
- Enable the SENT interrupts and set the interrupt priority.
- Set the ON bit (SENTxCON1[15]) to enable the module.
Incoming data are read from the SENTxDAT register after the completion of the CRC and before the next message frame’s status nibble. The recommended method is to use the message frame completion interrupt trigger.
SENT1 Reception Code
#include<xc.h> #define mFclk (4E+6) #define mTickTime (70E-6) #define mFrameTime (25E-3) #define mSyncCount (8 * mFclk * mTickTime) #define mSyncMin (0.8 * mSyncCount) #define mSyncMax (1.2 * mSyncCount) uint8_t ReceivedData[6]; uint8_t i; int main(void) { _SENT1R = 24; // RP24 as SENT1 RX pin SENT1CON1bits.RCVEN = 1; // Module operates as a receiver SENT1CON1bits.NIBCNT = 6; // 6 data nibbles per data packet SENT1CON1bits.CRCEN = 1; // CRC is calculated using the J2716 method SENT1CON1bits.PPP = 1; // SENTx messages transmitted with Pause Pulse SENT1CON1bits.PS = 0; // Module clock is FSENT SENT1CON2 = mSyncMax; // SYNCMAX SENT1CON3 = mSyncMin; // SYNCMIN _SENT1IE = 1; // Enable SENT1 interrupt _SENT1IP = 4; // set SENT interrupt priority SENT1CON1bits.ON = 1; // Enable SENT module while(1); return 0; } void __attribute__((__interrupt__,__auto_psv__)) _SENT1Interrupt (void) { _SENT1IF = 0; // Clear interrupt flag i=0; ReceivedData[i++] = SENT1DATbits.DATA1; // Read Data Nibble 1 ReceivedData[i++] = SENT1DATbits.DATA2; // Read Data Nibble 2 ReceivedData[i++] = SENT1DATbits.DATA3; // Read Data Nibble 3 ReceivedData[i++] = SENT1DATbits.DATA4; // Read Data Nibble 4 ReceivedData[i++] = SENT1DATbits.DATA5; // Read Data Nibble 5 ReceivedData[i++] = SENT1DATbits.DATA6; // Read Data Nibble 6 }