21.4.1.7 Synchronous Transmitter Mode
The module can be alternatively configured as a synchronous transmitter. In this mode, the module will transmit only one message frame each time the SYNCTXEN bit (SENTxSTAT[0]) is set. When the data frame is complete, the SYNCTXEN bit will be cleared in hardware. The line will be driven low for five ticks to complete the CRC nibble and then the line will tri-state and remain in the Idle state until SYNCTXEN is set again. An interrupt is generated, five ticks after the completion of the CRC nibble. Figure 21-6 shows the relationship between the control, status and interrupt events.
- Tick Time, TTICK (Equation 21-1)
- Number of Data Nibbles
- Hardware or Application Calculated CRC
- Clear the RCVEN bit (SENTxCON1[11]) for Transmit mode.
- Set the TXM bit (SENTxCON1[10]) for synchronous transmit operation.
- 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.
- Write the desired value for TICKTIME to SENTxCON2.
- Enable the SENT interrupts and set the interrupt priority.
- Set the ON bit (SENTxCON1[15]) to enable module.
- Write the data to be transmitted to the SENTxDAT register.
- Set the SYNCTXEN bit to begin transmission.
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 or poll the SYNCTXEN bit.
SENT1 Synchronous 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 = 1; // Synchronous 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
SENT1STATbits.SYNCTXEN = 1; // Initiate Synchronous Transmission
while(1);
return 0;
}
void __attribute__((__interrupt__,__auto_psv__)) _SENT1Interrupt (void)
{
_SENT1IF = 0; // Clear interrupt flag
// Update SENT1DAT here
}