English
Language : 

70353C Datasheet, PDF (62/76 Pages) Microchip Technology – Section 21. Enhanced Controller Area Network
dsPIC33E/PIC24E Family Reference Manual
Example 21-9: Code Example for Configuring ECAN™ Bit Timing Parameters
/* This code snippet shows an example of configuring the ECAN module to
operate at 1 Mbps while the device is operating at 40 MHz */
/* Set the Operating Frequency of the device to be 40 MHz */
#define FP 40000000
/* Set the ECAN module for Configuration Mode before writing into the Baud
Rate Control Registers */
C1CTRL1bits.REQOP = 4;
/* Wait for the ECAN module to enter into Configuration Mode */
while(C1CTRL1bits.OPMODE! = 4);
/* FCAN is selected to be FP by clearing the CANCKS bit
/* FCAN = FP = 40 MHz */
C1CTRL1bits.CANCKS = 0x0;
/* Phase Segment 1 time is 8 TQ */
C1CFG2bits.SEG1PH = 0x7;
/* Phase Segment 2 time is set to be programmable */
C1CFG2bits.SEG2PHTS = 0x1;
/* Phase Segment 2 time is 6 TQ */
C1CFG2bits.SEG2PH = 0x5;
/* Propagation Segment time is 5 TQ */
C1CFG2bits.PRSEG = 0x4;
/* Bus line is sampled three times at the sample point */
C1CFG2bits.SAM = 0x1;
/* Synchronization Jump Width set to 4 TQ */
C1CFG1bits.SJW = 0x3;
/* Baud Rate Prescaler bits set to 1:1, (i.e., TQ = (2*1*1)/FCAN) */
C1CFG1bits.BRP = 0x0;
/* Put the ECAN Module into Normal Operating Mode */
C1CTRL1bits.REQOP = 0;
/* Wait for the ECAN module to enter into Normal Operating Mode */
while(C1CTRL1bits.OPMODE! = 0);
DS70353C-page 21-62
© 2008-2011 Microchip Technology Inc.