English
Language : 

70353C Datasheet, PDF (36/76 Pages) Microchip Technology – Section 21. Enhanced Controller Area Network
dsPIC33E/PIC24E Family Reference Manual
Example 21-1: Code Example for Standard Data Frame Transmission (Continued)
/* Configure Message Buffer 0 for Transmission and assign priority */
C1TR01CONbits.TXEN0 = 0x1;
C1TR01CONbits.TX0PRI = 0x3;
/* At this point the ECAN1 module is ready to transmit a message. Place the ECAN module in
Normal mode. */
C1CTRL1bits.REQOP = 0;
while(C1CTRL1bits.OPMODE != 0);
/* Write to message buffer 0 */
/* CiTRBnSID = 0bxxx1 0010 0011 1100
IDE = 0b0
SRR = 0b0
SID<10:0>= 0b100 1000 1111 */
ecan1MsgBuf[0][0] = 0x123C;
/* CiTRBnEID = 0bxxxx 0000 0000 0000
EID<17:6> = 0b0000 0000 0000 */
ecan1MsgBuf[0][1] = 0x0000;
/* CiTRBnDLC = 0b0000 0000 xxx0 1111
EID<17:6> = 0b000000
RTR = 0b0
RB1 = 0b0
RB0 = 0b0
DLC = 0b1111 */
ecan1MsgBuf[0][2] = 0x0008;
/* Write message data bytes */
ecan1MsgBuf[0][3] = 0xabcd;
ecan1MsgBuf[0][4] = 0xabcd;
ecan1MsgBuf[0][5] = 0xabcd;
ecan1MsgBuf[0][6] = 0xabcd;
/* Request message buffer 0 transmission */
C1TR01CONbits.TXREQ0 = 0x1;
/* The following shows an example of how the TXREQ bit can be polled to check if transmission
is complete. */
while(C1TR01CONbits.TXREQ0 == 1);
/* Message was placed successfully on the bus */
while(1);
}
A code example to transmit an extended frame using Message Buffer 2 is shown in
Example 21-2.
DS70353C-page 21-36
© 2008-2011 Microchip Technology Inc.