21.4.1.6 Asynchronous Transmitter Mode

The module is, by default, configured as an asynchronous transmitter. In this mode, the module continuously transmits message frames as long as the ON bit is set (SENTxCON1[15]). The final falling edge of the CRC nibble also serves as the first falling edge of the Sync pulse. An interrupt is generated at the completion of the CRC nibble.

Figure 21-4 and Figure 21-5 show the relationship between the control, status and interrupt events.

Figure 21-4. SENTx Data Transmission, Asynchronous Mode
Figure 21-5. SENTx Data Transmission with Pause Period
To fully configure the module, the following must be known:
  • Tick Time, TTICK (Equation 21-1)
  • Number of Data Nibbles, N
  • Hardware or Application Calculated CRC
  • Use of Pause Period for Fixed Message Period
  • The Overall Duration of the SENT Message if the Pause Period is Present (Equation 21-2)
To initialize the module:
  1. Clear RCVEN (SENTxCON1[11]) for Transmit mode.
  2. Clear TXM (SENTxCON1[10]) for asynchronous transmit.
  3. Write the value of the desired frame length to NIBCNT[2:0] (SENTxCON1<2:0>).
  4. Set or clear CRCEN (SENTxCON1[8]) to configure the module for hardware or software CRC calculation.
  5. Write the value for the desired TICKTIME to SENTxCON2.
  6. If the optional Pause period is required, set PPP (SENTxCON1[7]) to enable the feature, then write the value of FRAMETIME to SENTxCON3.
  7. Enable the SENT interrupt(s) and set the interrupt priority.
  8. Write the initial status and data values to SENTxDAT. If application-based CRC is being used (CRCEN = 0), also calculate the message CRC and write it to CRC<[:0].
  9. Set ON (SENTxCON1[15]) to enable the module.

Updates to SENTxDAT must be performed 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 to trigger data writes.

SENT1 Asynchronous Transmission Code

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#define mFclk (4E+6)
#define mTickTime (70E-6)
#define mFrameTime (25E-3)
int main(void) {
    _RP23R = 57; // Assign SENT1OUT to pin RP23
    SENT1CON1bits.RCVEN = 0; // Module operates as a transmitter
    SENT1CON1bits.TXM = 0; // Asynchronous Transmit
    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 = ( (mTickTime * mFclk) - 1); // TICKTIME
    SENT1CON3 = ( mFrameTime / mTickTime) ; // FRAMETIME
    _SENT1IE = 1; // Enable SENT1 interrupt
    _SENT1IP = 4; // SENT interrupt priority
    SENT1DATbits.STAT = 0; // Status Nibble
    SENT1DATbits.DATA1 = 1; // Data Nibble 1
    SENT1DATbits.DATA2 = 2; // Data Nibble 2
    SENT1DATbits.DATA3 = 3; // Data Nibble 3
    SENT1DATbits.DATA4 = 4; // Data Nibble 4
    SENT1DATbits.DATA5 = 5; // Data Nibble 5
    SENT1DATbits.DATA6 = 6; // Data Nibble 6
    SENT1CON1bits.ON = 1; // Enable SENT module
    while(1);
    return 0;
}
void __attribute__((__interrupt__,__auto_psv__)) _SENT1Interrupt (void)
{
    _SENT1IF = 0; // Clear interrupt flag
    // Update SENT1DAT here
}