Can Module
Can Module
Can Module
HIGHLIGHTS
This section of the manual contains the following major topics:
CAN Module
23.13 Operation in CPU Power Saving Modes.................................................................... 23-68
23.14 CAN Protocol Overview ............................................................................................. 23-70
23.15 Related Application Notes.......................................................................................... 23-74
23.16 Revision History ......................................................................................................... 23-75
23.1 Introduction
The Controller Area Network (CAN) module is a serial interface useful for communicating with
other peripherals or microcontroller devices. This interface/protocol was designed to allow
communications within noisy environments. Figure 23-1 shows an example CAN bus network.
dsPIC30F
with CAN
MCP2551
CAN Transceiver
bus
Microchip
MCP2510
SPI™
Interface dsPIC30F dsPIC30F PICmicro
PICmicro® with integrated with integrated with integrated
Microcontroller CAN CAN CAN
Note 1: ‘i’ in the register identifier denotes the specific CAN module (CAN1 or CAN2).
2: ‘n’ in the register identifier denotes the buffer, filter or mask number.
3: ‘m’ in the register identifier denotes the word number within a particular CAN data
field.
Lower Byte:
R-1 R-0 R-0 U-0 R-0 R-0 R-0 U-0
OPMODE<2:0> — ICODE<2:0> —
bit 7 bit 0
CAN Module
Note: Module will clear this bit when all transmissions aborted.
bit 11 CANCKS: CAN Master Clock Select bit
1 = FCAN clock is FCY
0 = FCAN clock is 4 FCY
bit 10-8 REQOP<2:0>: Request Operation Mode bits
111 = Set Listen All Messages mode
110 = Reserved
101 = Reserved
100 = Set Configuration mode
011 = Set Listen Only mode
010 = Set Loopback mode
001 = Set Disable mode
000 = Set Normal Operation mode
bit 7-5 OPMODE<2:0>: Operation Mode bits
Note: These bits indicate the current Operating mode of the CAN module. See description for REQOP
bits (CiCTRL<10:8>).
bit 4 Unimplemented: Read as ‘0’
Register 23-1: CiCTRL: CAN Module Control and Status Register (Continued)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R-0 R-0 R-0 R/W-0 U-0 R/W-0 R/W-0
— TXABT TXLARB TXERR TXREQ — TXPRI<1:0>
bit 7 bit 0
CAN Module
Note: This bit is cleared when TXREQ is set.
bit 4 TXERR: Error Detected During Transmission bit
1 = A bus error occurred while the message was being sent
0 = A bus error did not occur while the message was being sent
Note: This bit is cleared when TXREQ is set.
bit 3 TXREQ: Message Send Request bit
1 = Request message transmission
0 = Abort message transmission if TXREQ already set, otherwise no effect
Note: The bit will automatically clear when the message is successfully sent.
bit 2 Unimplemented: Read as ‘0’
bit 1-0 TXPRI<1:0>: Message Transmission Priority bits
11 = Highest message priority
10 = High intermediate message priority
01 = Low intermediate message Priority
00 = Lowest message priority
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
SID<5:0> SRR TXIDE
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
EID<13:6>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x U-0 U-0 U-0
TXRB0 DLC<3:0> — — —
bit 7 bit 0
Legend: 23
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
CAN Module
-n = Value at POR ‘1’ = Bit is set ‘0’ = bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
CTXB<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = bit is cleared x = Bit is unknown
Lower Byte:
R/C-0 U-0 U-0 U-0 R-0 R/W-0 R/W-0 R-0
RXFUL — — — RXRTRRO DBEN JTOFF FILHIT0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit C = Bit can be cleared U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/C-0 U-0 U-0 U-0 R-0 R-0 R-0 R-0
RXFUL — — — RXRTRRO FILHIT<2:0>
bit 7 bit 0
CAN Module
100 = Acceptance filter 4 (RXF4)
011 = Acceptance filter 3 (RXF3)
010 = Acceptance filter 2 (RXF2)
001 = Acceptance filter 1 (RXF1) (Only possible when DBEN bit is set)
000 = Acceptance filter 0 (RXF0) (Only possible when DBEN bit is set)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
SID<5:0> SRR RXIDE
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
EID<13:6>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
CRXB<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
CAN Module
EID<5:0> RXRTR RB1
bit 15 bit 8
Lower Byte:
U-0 U-0 U-0 R/W-x R/W-x R/W-x R/W-x R/W-x
— — — RB0 DLC<3:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x U-0 R/W-x
SID<5:0> — EXIDE
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
EID<13:6>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— — — — — — — —
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
23
CAN Module
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x U-0 R/W-x
SID<5:0> — MIDE
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
EID<13:6>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— — — — — — — —
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
23
CAN Module
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SJW<1:0> BRP<5:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x R/W-x
SEG2PHT SAM SEG1PH<2:0> PRSEG<2:0>
S
bit 7 bit 0
CAN Module
1 = Freely programmable
0 = Maximum of SEG1PH or information processing time (3 TQ’s), whichever is greater
bit 6 SAM: Sample of the CAN bus Line bit
1 = Bus line is sampled three times at the sample point
0 = Bus line is sampled once at the sample point
bit 5-3 SEG1PH<2:0>: Phase Buffer Segment 1 bits
111 = length is 8 x TQ
.
.
000 = length is 1 x TQ
bit 2-0 PRSEG<2:0>: Propagation Time Segment bits
111 = length is 8 x TQ
.
.
000 = length is 1 x TQ
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R-0 R-0 R-0 R-0 R-0 R-0 R-0 R-0
RERRCNT<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
IVRIE WAKIE ERRIE TX2IE TX1IE TX0IE RX1IE RX0IE
bit 7 bit 0
CAN Module
0 = Disabled
bit 4 TX2IE: Transmit Buffer 2 Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 3 TX1IE: Transmit Buffer 1 Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 2 TX0IE: Transmit Buffer 0 Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 1 RX1IE: Receive Buffer 1 Interrupt Enable bit
1 = Enabled
0 = Disabled
bit 0 RX0IE: Receive Buffer 0 Interrupt Enable bit
1 = Enabled
0 = Disabled
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
IVRIF WAKIF ERRIF TX2IF TX1IF TX0IF RX1IF RX0IF
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit C = Bit can be cleared U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
23
CAN Module
DS70070B-page 23-22
unused 306 — — — — — — — — — — — — — — — — XXXX
C1RXF1SID 308 — — — SID<10:6> SID<5:0> — EXIDE XXXX
C1RXF1EIDH 30A — — — — EID<17:14> EID<13:6> XXXX
C1RXF1EIDL 30C EID<5:0> — — — — — — — — — — XXXX
unused 30E — — — — — — — — — — — — — — — — XXXX
C1RXF2SID 310 — — — SID<10:6> SID<5:0> — EXIDE XXXX
C1RXF2EIDH 312 — — — — EID<17:14> EID<13:6> XXXX
C1RXF2EIDL 314 EID<5:0> — — — — — — — — — — XXXX
unused 316 — — — — — — — — — — — — — — — — XXXX
C1RXF3SID 318 — — — SID<10:6> SID<5:0> — EXIDE XXXX
C1RXF3EIDH 31A — — — — EID<17:14> EID<13:6> XXXX
C1RXF3EIDL 31C EID<5:0> — — — — — — — — — — XXXX
unused 31E — — — — — — — — — — — — — — — — XXXX
C1RXF4SID 320 — — — SID<10:6> SID<5:0> — EXIDE XXXX
dsPIC30F Family Reference Manual
Advance Information
unused 326 — — — — — — — — — — — — — — — — XXXX
C1RXF5SID 328 — — — SID<10:6> SID<5:0> — EXIDE XXXX
C1RXF5EIDH 32A — — — — EID<17:14> EID<13:6> XXXX
C1RXF5EIDL 32C EID<5:0> — — — — — — — — — — XXXX
unused 32E — — — — — — — — — — — — — — — — XXXX
C1RXM0SID 330 — — — SID<10:6> SID<5:0> — MIDE XXXX
C1RXM0EIDH 332 — — — — EID<17:14> EID<13:6> XXXX
C1RXM0EIDL 334 EID<5:0> — — — — — — — — — — XXXX
unused 336 — — — — — — — — — — — — — — — — XXXX
C1RXM1SID 338 — — — SID<10:6> SID<5:0> — MIDE XXXX
C1RXM1EIDH 33A — — — — EID<17:14> EID<13:6> XXXX
C1RXM1EIDL 33C EID<5:0> — — — — — — — — — — XXXX
unused 33E — — — — — — — — — — — — — — — — XXXX
Advance Information
— — —
IDE
C1TX0EID 362 EID<17:14> — — — — EID<13:6> xxxx
C1TX0DLC 362 EID<5:0> TX TX TX DLC<3:0> — — — xxxx
RTR RB1 RB0
C1TX0D01 366 Transmit Buffer 0 Byte 1 Transmit Buffer 0 Byte 0 xxxx
C1TX0D23 368 Transmit Buffer 0 Byte 3 Transmit Buffer 0 Byte 2 xxxx
C1TX0D45 36A Transmit Buffer 0 Byte 5 Transmit Buffer 0 Byte 4 xxxx
C1TX0D67 36C Transmit Buffer 0 Byte 7 Transmit Buffer 0 Byte 6 xxxx
C1TX0CON 36E — — — — — — — — — TX TX TX TX — TXPRI[1:0] 0000
ABT LARB ERR REQ
DS70070B-page 23-23
Section 23. CAN
23
CAN Module
Table 23-1: CAN1 Register Map (Continued)
Bit
File Name ADR RESET
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DS70070B-page 23-24
C1RX1DLC 374 EID<0:5> RX RX — — — RX DLC[3:0] xxxx
RTR RB1 RB0
C1RX1D01 376 Receive Buffer 1 Byte 1 Receive Buffer 1 Byte 0 xxxx
C1RX1D23 378 Receive Buffer 1 Byte 3 Receive Buffer 1 Byte 2 xxxx
C1RX1D45 37A Receive Buffer 1 Byte 5 Receive Buffer 1 Byte 4 xxxx
C1RX1D67 37C Receive Buffer 1 Byte 7 Receive Buffer 1 Byte 6 xxxx
C1RX1CON 37E RX RX RX FILHIT[2:0] 0000
— — — — — — — — — —
FUL ERR RTR
R0
C1RX1SID 380 — — — SID<10:6> SID<5:0> SRR RX xxxx
IDE
C1RX1EID 382 — — — — EID<17:14> EID<13:6> xxxx
C1RX1DLC 384 EID<0:5> RX RX — — — RX DLC[3:0] xxxx
RTR RB1 RB0
C1RX0D01 386 Receive Buffer 0 Byte 1 Receive Buffer 0 Byte 0 xxxx
C1RX0D23 388 Receive Buffer 0 Byte 3 Receive Buffer 0 Byte 2 xxxx
C1RX0D45 38A Receive Buffer 0 Byte 5 Receive Buffer 0 Byte 4 xxxx
dsPIC30F Family Reference Manual
Advance Information
R0 0
C1CTRL 390 CAN CAN CAN ABAT CAN REQOP[2:0] OPMODE[2:0] — ICODE[2:0] — 0480
CAP FRZ SIDL CKS
C1CFG1 392 — — — — — — — — SJW[1:0]S BRP[5:0] 0000
C1CFG2 394 — WAK — — — SEG2PH[2:0] SEG2 SAM SEG1PH[2:0] PRSEG[2:0] 0000
FIL PHTS
C1INTF 396 RXB0 RXB1 TXBO TXBP RXBP TX RX E IVR WAK ERR TXB2 TXB1 TXB0 RXB1 RXB0 0000
OVR OVR WARN WARN WARN IF IF IF IF IF IF IF IF
C1INTE 398 — — — — — — — — IVR WAK ERR TXB2 TXB1 TXB0 RXB1 RXB0 0000
IE IE IE IE IE IE IE IE
C1TREC 39A Transmit Error Counter Receive Error Counter 0000
Reserved 39C — — — — — — — — — — — — — — — — xxxx
3FE
Legend: x = Unknown
Advance Information
unused 426 — — — — — — — — — — — — — — — — xxxx
C2RXF5SID 428 — — — SID<10:6> SID<5:0> — EXIDE xxxx
C2RXF5EIDH 42A — — — — EID<17:14> EID<13:6> xxxx
C2RXF5EIDL 42C EID<5:0> — — — — — — — — — — xxxx
unused 42E — — — — — — — — — — — — — — — — xxxx
C2RXM0SID 430 — — — SID<10:6> SID<5:0> — MIDE xxxx
C2RXM0EIDH 432 — — — — EID<17:14> EID<13:6> xxxx
C2RXM0EIDL 434 EID<5:0> — — — — — — — — — — xxxx
unused 436 — — — — — — — — — — — — — — — — xxxx
C2RXM1SID 438 — — — SID<10:6> SID<5:0> — MIDE xxxx
C2RXM1EIDH 43A — — — — EID<17:14> EID<13:6> xxxx
C2RXM1EIDL 43C EID<5:0> — — — — — — — — — — xxxx
unused 43E — — — — — — — — — — — — — — — — xxxx
DS70070B-page 23-25
Section 23. CAN
23
CAN Module
Table 23-2: CAN2 Register Map (Continued)
File Name ADR Bit RESET
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DS70070B-page 23-26
C2TX2DLC 442 EID<5:0> TX TX TX DLC<3:0> — — — xxxx
RTR RB1 RB0
C2TX2D01 446 Transmit Buffer 0 Byte 1 Transmit Buffer 0 Byte 0 xxxx
C2TX2D23 448 Transmit Buffer 0 Byte 3 Transmit Buffer 0 Byte 2 xxxx
C2TX2D45 44A Transmit Buffer 0 Byte 5 Transmit Buffer 0 Byte 4 xxxx
C2TX2D67 44C Transmit Buffer 0 Byte 7 Transmit Buffer 0 Byte 6 xxxx
C2TX2CON 44E — — — — — — — — — TX TX TX TX — TXPRI[1:0] 0000
ABT LARB ERR REQ
C2TX1SID 450 SID<10:6> — — — SID<5:0> SRR TX xxxx
IDE
C2TX1EID 452 EID<17:14> — — — — EID<13:6> xxxx
C2TX1DLC 352 EID<5:0> TX TX TX DLC<3:0> — — — xxxx
RTR RB1 RB0
C2TX1D01 456 Transmit Buffer 0 Byte 1 Transmit Buffer 0 Byte 0 xxxx
C2TX1D23 458 Transmit Buffer 0 Byte 3 Transmit Buffer 0 Byte 2 xxxx
C2TX1D45 45A Transmit Buffer 0 Byte 5 Transmit Buffer 0 Byte 4 xxxx
C2TX1D67 45C Transmit Buffer 0 Byte 7 Transmit Buffer 0 Byte 6 xxxx
dsPIC30F Family Reference Manual
Advance Information
C2TX0SID 460 SID<10:6> — — — SID<5:0> SRR TX xxxx
IDE
C2TX0EID 462 EID<17:14> — — — — EID<13:6> xxxx
C2TX0DLC 462 EID<5:0> TX TX TX DLC<3:0> — — — xxxx
RTR RB1 RB0
C2TX0D01 466 Transmit Buffer 0 Byte 1 Transmit Buffer 0 Byte 0 xxxx
C2TX0D23 468 Transmit Buffer 0 Byte 3 Transmit Buffer 0 Byte 2 xxxx
C2TX0D45 46A Transmit Buffer 0 Byte 5 Transmit Buffer 0 Byte 4 xxxx
C2TX0D67 46C Transmit Buffer 0 Byte 7 Transmit Buffer 0 Byte 6 xxxx
C2TX0CON 46E — — — — — — — — — TX TX TX TX — TXPRI[1:0] 0000
ABT LARB ERR REQ
Advance Information
R0 0
C2CTRL 490 CAN CAN CAN ABAT CAN REQOP[2:0] OPMODE[2:0] — ICODE[2:0] — 0480
CAP FRZ SIDL CKS
C2CFG1 492 — — — — — — — — SJW[1:0]S BRP[5:0] 0000
C2CFG2 494 — WAK — — — SEG2PH[2:0] SEG2 SAM SEG1PH[2:0] PRSEG[2:0] 0000
FIL PHTS
C2INTF 496 RXB0 RXB1 TXBO TXBP RXBP TX RX E IVR WAK ERR TXB2 TXB1 TXB0 RXB1 RXB0 0000
OVR OVR WARN WARN WARN IF IF IF IF IF IF IF IF
C2INTE 498 — — — — — — — — IVR WAK ERR TXB2 TXB1 TXB0 RXB1 RXB0 0000
IE IE IE IE IE IE IE IE
C2TREC 49A Transmit Error Counter Receive Error Counter 0000
Reserved 49C — — — — — — — — — — — — — — — — xxxx
4FE
Legend: x = Unknown
DS70070B-page 23-27
Section 23. CAN
23
CAN Module
dsPIC30F Family Reference Manual
Acceptance Mask
BUFFERS RXM1
Acceptance Filter
RXF2
MESSAGE
MESSAGE
MTXBUFF
MTXBUFF
MTXBUFF
MSGREQ
MSGREQ
MSGREQ
TXLARB
TXLARB
TXLARB
c RXF0 RXF4 p
TXERR
TXERR
TXERR
TXABT
TXABT
TXABT
e t
Acceptance Filter Acceptance Filter
p
RXF1 RXF5
t
R Message R
X Identifier Assembly Identifier X
Message B B
Queue 0 Buffer 1
Control
Transmit Byte Sequencer Data Field Data Field
23
CAN Module
Receive RERRCNT
Error
Counter
PROTOCOL TERRCNT
ENGINE
Transmit ErrPas
Error BusOff
Counter
Protocol
Finite
CRC Generator CRC Check
State
Machine
Bit
Transmit
Timing Bit Timing
Logic
Logic Generator
CxTX CxRX
Note: x = 1 or 2
A standard data frame is generated by a node when the node wishes to transmit data. The
standard CAN data frame is shown in Figure 23-3. In common with all other frames, the frame
begins with a Start-Of-Frame bit (SOF - dominant state) for hard synchronization of all nodes.
The SOF is followed by the Arbitration field consisting of 12 bits, the 11-bit identifier (reflecting
the contents and priority of the message) and the RTR bit (Remote Transmission Request bit).
The RTR bit is used to distinguish a data frame (RTR - dominant) from a remote frame.
The next field is the Control field, consisting of 6 bits. The first bit of this field is called the Identifier
Extension (IDE) bit and is at dominant state to specify that the frame is a standard frame. The
following bit is reserved by the CAN protocol, RB0, and defined as a dominant bit. The remaining
4 bits of the Control field are the Data Length Code (DLC) and specify the number of bytes of
data contained in the message.
The data being sent follows in the Data field which is of the length defined by the DLC above (0-8
bytes).
The Cyclic Redundancy Check (CRC) field follows and is used to detect possible transmission
errors. The CRC field consists of a 15-bit CRC sequence and a delimiter bit. The message is
completed by the End-Of-Frame (EOF) field, which consists of seven recessive bits with no
bit-stuffing.
The final field is the Acknowledge field. During the ACK Slot bit the transmitting node sends out
a recessive bit. Any node that has received an error free frame acknowledges the correct
reception of the frame by sending back a dominant bit (regardless of whether the node is
configured to accept that specific message or not). The recessive Acknowledge Delimiter
completes the Acknowledge Slot and may not be overwritten by a dominant bit, except when an
error frame occurs.
In the extended CAN data frame, shown in Figure 23-4, the Start-Of-Frame bit (SOF) is followed
by the Arbitration Field consisting of 38 bits. The first 11 bits are the 11 Most Significant bits of
the 29-bit identifier (“Base-lD”). These 11 bits are followed by the Substitute Remote Request bit
(SRR), which is transmitted as recessive. The SRR is followed by the lDE bit which is recessive
to denote that the frame is an extended CAN frame. It should be noted from this, that if arbitration
remains unresolved after transmission of the first 11 bits of the identifier, and one of the nodes
involved in arbitration is sending a standard CAN frame (11-bit identifier), then the standard CAN
frame will win arbitration due to the assertion of a dominant lDE bit. Also, the SRR bit in an
extended CAN frame must be recessive to allow the assertion of a dominant RTR bit by a node
that is sending a standard CAN remote frame. The SRR and lDE bits are followed by the remain-
ing 18 bits of the identifier (“lD-Extension”) and a dominant Remote Transmission Request bit.
To enable standard and extended frames to be sent across a shared network, it is necessary to
split the 29-bit extended message identifier into 11-bit (Most Significant) and 18-bit (Least Signif-
icant) sections. This split ensures that the Identifier Extension bit (lDE) can remain at the same
bit position in both standard and extended frames.
The next field is the Control field, consisting of 6 bits. The first 2 bits of this field are reserved and
are at dominant state. The remaining 4 bits of the Control field are the Data Length Code (DLC)
and specify the number of data bytes.
The remaining portion of the frame (Data field, CRC field, Acknowledge field, End-Of-Frame and
intermission) is constructed in the same way as for a standard data frame.
A data transmission is usually performed on an autonomous basis with the data source node
(e.g., a sensor sending out a data frame). It is possible however for a destination node to request
the data from the source. For this purpose, the destination node sends a “remote frame” with an
identifier that matches the identifier of the required data frame. The appropriate data source node
will then send a data frame as a response to this remote request.
There are two differences between a remote frame and a data frame, shown in Figure 23-5. First,
the RTR bit is at the recessive state and second there is no Data field. In the very unlikely event
of a data frame and a remote frame with the same identifier being transmitted at the same time,
the data frame wins arbitration due to the dominant RTR bit following the identifier. In this way,
the node that transmitted the remote frame receives the desired data immediately.
An error frame is generated by any node that detects a bus error. An error frame, shown in 23
Figure 23-6, consists of 2 fields, an error flag field followed by an Error Delimiter field. The Error
Delimiter consists of 8 recessive bits and allows the bus nodes to restart bus communications
CAN Module
cleanly after an error. There are two forms of error flag fields. The form of the error flag field
depends on the error status of the node that detects the error.
If an error-active node detects a bus error then the node interrupts transmission of the current
message by generating an active error flag. The active error flag is composed of six consecutive
dominant bits. This bit sequence actively violates the bit-stuffing rule. All other stations recognize
the resulting bit-stuffing error and in turn generate error frames themselves, called Error Echo
Flags. The error flag field therefore consists of between six and twelve consecutive dominant bits
(generated by one or more nodes). The Error Delimiter field completes the error frame. After
completion of the error frame, bus activity retains to normal and the interrupted node attempts to
resend the aborted message.
If an error passive node detects a bus error then the node transmits an Error Passive flag
followed, again, by the Error Delimiter field. The Error Passive flag consists of six consecutive
recessive bits. From this it follows that, unless the bus error is detected by the transmitting node
or other error active receiver that is actually transmitting, the transmission of an error frame by
an error passive node will not affect any other node on the network. If the bus master node
generates an error passive flag then this may cause other nodes to generate error frames due
to the resulting bit-stuffing violation. After transmission of an error frame, an error passive node
must wait for 6 consecutive recessive bits on the bus before attempting to rejoin bus
communications.
An overload frame, shown in Figure 23-7, has the same format as an active error frame. An
overload frame, however can only be generated during lnterframe Space. This way, an overload
frame can be differentiated from an error frame (an error frame is sent during the transmission of
a message). The overload frame consists of 2 fields, an overload flag followed by an Overload
Delimiter. The overload flag consists of six dominant bits followed by overload flags generated
by other nodes (as for active error flag, again giving a maximum of twelve dominant bits). The
Overload Delimiter consists of eight recessive bits. An overload frame can be generated by a
node as a result of 2 conditions. First, the node detects a dominant bit during lnterframe Space
which is an illegal condition. Second, due to internal conditions, the node is not yet able to start
reception of the next message. A node may generate a maximum of 2 sequential overload
frames to delay the start of the next message.
Interframe Space separates a proceeding frame (of whatever type) from a following data or
remote frame. lnterframe Space is composed of at least 3 recessive bits, called the intermission.
This is provided to allow nodes time for internal processing of the message by receiving nodes
before the start of the next message frame. After the intermission, the bus line remains in the
recessive state (bus idle) until the next transmission starts.
If the transmitting node is in the error passive state, an additional 8 recessive bit times will be
inserted in the Interframe Space before any other message is transmitted by that node. This time
period is called the Suspend Transmit field. The Suspend Transmit field allows additional delay
time for other transmitting nodes to take control of the bus.
Inter-Frame Space
Start-Of-Frame
111111111111111111111 1110
Start-Of-Frame
ACK Del
Acknowledgment
CRC Del
DLC3
ID 10
ID3
ID0
DLC0
IDE
RB0
RTR
0 000 00000000 1 11111111
Identifier Data
Length
Code
Message
Filtering Inter-Frame Space
Stored in Transmit/Receive Buffers
Reserved Bits
Stored in Buffers 3 8 Data Frame or
Advance Information
Bit-Stuffing Any Frame INT Suspend bus Idle Remote Frame
Transmit
Start-Of-Frame
111111111111111111111 1110
DS70070B-page 23-33
Section 23. CAN
CAN Module
23
Figure 23-4:
DS70070B-page 23-34
Data Frame or
bus Idle Remote Frame
Start-Of-Frame
Extended Data Format
11 1110
ID10
ID3
SRR
IDE
EID17
EID0
RTR
RB1
RB0
DLC3
DLC0
ID0
CRC Del
Start-Of-Frame
0 11 100 000000000000000000000001 11111111
Data
Identifier Extended Identifier Length
dsPIC30F Family Reference Manual
Code
Message
Filtering
Reserved bits
Stored in Buffers Stored in Transmit/Receive Buffers
Advance Information
Inter-Frame Space
Bit-Stuffing 3 8 Data Frame or
Any Frame INT Suspend bus Idle Remote Frame
Transmit
Start-Of-Frame
111111111111111111111 1110
3 8 Data Frame or
Remote Data Frame
Start-Of-Frame
111111111111111111111 1110
Start-Of-Frame
ACK Del
Acknowledgment
CRC Del
DLC3
ID 10
ID0
IDE
DLC0
RB0
RTR
0 100 1 11111111
Identifier Data
Length
Message Code Inter-Frame Space
Advance Information
Filtering
3 8 Data Frame or
Reserved Bits
Stored in Buffers Any Frame INT Remote Frame
Suspend bus Idle
Transmit
Bit-Stuffing
Start-Of-Frame
111111111111111111111 1110
DS70070B-page 23-35
Section 23. CAN
CAN Module
23
Figure 23-6:
DS70070B-page 23-36
Inter-Frame Space
3 8 Data Frame or
Any Frame INT Suspend bus Idle Remote Frame
Error Frame
Transmit
Start-Of-Frame
111111111111111111111 1110
Start-Of-Frame
DLC3
ID 10
ID3
ID0
DLC0
IDE
RB0
RTR
0 000
Identifier Data
Length
Code
Message
Filtering
Reserved Bits
Error Frame
Bit-Stuffing
dsPIC30F Family Reference Manual
6 ≤6 8
Data Frame or Inter-Frame Space or
Remote Frame Error Echo Error Overload Frame
Flag Error Delimiter
Flag
Advance Information
0000000 00111111110
Inter-Frame Space
3 8 Data Frame or
Any Frame INT Suspend bus Idle Remote Frame
Transmit
Star-Of-Frame
111111111111111111111 1110
Inter-Frame Space
3 8 Data Frame or
Transmit
Start-Of-Frame
111111111111111111111 1110
Start-Of-Frame
ACK Del
Acknowledgment
CRC Del
DLC3
ID 10
ID0
DLC0
IDE
RB0
RTR
0 100 1 11111111
Overload Frame
End-Of-Frame or Inter-Frame Space or
Error Delimiter or 6 8 Error Frame
Overload Delimiter
Overload Overload
Flag Delimiter
Advance Information
00000011111111
Inter-Frame Space
3 8 Data Frame or
Any Frame INT Suspend bus Idle Remote Frame
Transmit
Start-Of-Frame
111111111111111111111 1110
DS70070B-page 23-37
Section 23. CAN
CAN Module
23
dsPIC30F Family Reference Manual
OSC1
REQOP<2:0> 001
000 000
CAN bus
WAKIF
WAKIE
CAN Module
Disabled
1 2 3 4 5
1 - Processor writes REQOP<2:0> while module receiving/transmitting message. Module continues with CAN message. 23
2 - Module detects 11 recessive bits. Module acknowledges Disable mode and sets OPMODE<2:0> bits. Module disables.
3 - CAN bus message will set WAKIF bit. If WAKIE = ’1’, processor will vector to the interrupt address. CAN message ignored.
CAN Module
4 - Processor writes REQOP<2:0> during CAN bus activity. Module waits for 11 recessive bits before accepting activate.
5 - Module detects 11 recessive bits. Module acknowledges Normal mode and sets OPMODE<2:0> bits. Module activates.
CAN Module
Note: In the case of Receive Buffer 0, a limited number of Acceptance Filters can be used
to enable a reception. A single bit, FILHIT0 (CiRX0CON<0>) determines which of
the 2 filters, RXF0 or RXF1, enabled the message reception.
To provide flexibility, there are several acceptance filters corresponding to each receive buffer.
There is also an implied priority to the receive buffers. RXB0 is the higher priority buffer and has
2 message acceptance filters associated with it. RXB1 is the lower priority buffer and has 4
acceptance filters associated with it. The lower number of possible acceptance filters makes the
match on RXB0 more restrictive and implies the higher priority associated with that buffer.
Additionally, if the RXB0 contains a valid message, and another valid message is received, the
RXB0 can be setup such that it will not overrun and the new message for RXB0 will be placed
into RXB1. Figure 23-9 shows a block diagram of the receive buffer, while Figure 23-10 shows a
flow chart for a receive operation.
Acceptance Mask
RXM1
Acceptance Filter
RXF2
R R
X Identifier Message Identifier X
Assembly
B B
Buffer
0 1
START
Detect
No Start of
Message
?
Yes
Generate Valid
No Message
Error
Frame Received
?
Yes
Go to Start
The RXFUL bit determines if the
receive register is empty and
23
able to accept a new message.
CAN Module
The DBEN bit determines if
RXB0 can roll over into
RXB1 if it is full.
Is No Is Yes
RXFUL = 0 DBEN = 1
? ?
Yes No
No Is
Move message into RXB0 Generate Overrun Error: Generate Overrun Error: RXFUL = 0
Set RX0OVR Set RX1OVR
?
Is Does
Generate Yes
RXnIE = 1 RXnIE = 1
? Interrupt
Yes ?
No No
Set ICODE<3:0> according
to which receive buffer the
message was loaded into
The EXIDE control bits (CiRXFnSID<0>) and the MIDE control bits (CiRXMnSID<0>) enable an
acceptance filter for standard or extended identifiers. The acceptance filters look at incoming
messages for the RXIDE bit to determine how to compare the identifiers. If the RXIDE bit is clear,
the message is a standard frame. If the RXIDE bit is set, the message is an extended frame.
If the MIDE control bit for the filter is set, then the identifier type for the filter is determined by the
EXIDE control bit for the filter. If the EXIDE control bit is cleared, then the filter will accept
standard identifiers. If the EXIDE bit is set, then the filter will accept extended identifiers. Most
CAN systems will use only standard identifiers or only extended identifiers.
If the MIDE control bit for the filter is cleared, the filter will accept both standard and extended
identifiers if a match occurs with the filter bits. This mode can be used in CAN systems that
support both standard and extended identifiers on the same bus.
As shown in the Receive Buffers Block Diagram, Figure 23-9, RXF0 and RXF1 filters with the
RXM0 mask are associated with RXB0. The filters RXF2, RXF3, RXF4 and RXF5 and the mask
RXM1 are associated with RXB1. When a filter matches and a message is loaded into the
receive buffer, the number of the filter that enabled the message reception is indicated in the
CiRXnCON register via the FILHIT bits. The CiRX0CON register contains one FILHIT Status bit
to indicate whether the RXF0 or the RXF1 filter enabled the message reception. The CiRX1CON
register contains the FILHIT<2:0> bits. They are coded as shown in Table 23-4.
The DBEN bit (CiRX0CON<2>) allows the FILHIT bits to distinguish a hit on filter RXF0 and
RXF1 in either RXB0 or overrun into RXB1.
111 = Acceptance Filter 1 (RXF1)
110 = Acceptance Filter 0 (RXF0)
001 = Acceptance Filter 1 (RXF1)
000 = Acceptance Filter 0 (RXF0)
If the DBEN bit is clear, there are 6 codes corresponding to the 6 filters. If the DBEN bit is set,
there are 6 codes corresponding to the 6 filters plus 2 additional codes corresponding to RXF0
and RXF1 filters overrun to RXB1.
If more than 1 acceptance filter matches, the FILHIT bits will encode the lowest binary value of
the filters that matched. In other words, if filter 2 and filter 4 match, FILHIT will code the value for
2. This essentially prioritizes the acceptance filters with lower numbers having priority.
23
Figure 23-11 shows a block diagram of the message acceptance filters.
CAN Module
Figure 23-11: Message Acceptance Filter
RXFn0 RXMn0
RXMn1 RxRqst
RXFn1
RXMnn
RXFnn
With the Cyclic Redundancy Check, the transmitter calculates special check bits for the bit
sequence from the start of a frame until the end of the data field. This CRC sequence is
transmitted in the CRC Field. The receiving node also calculates the CRC sequence using the
same formula and performs a comparison to the received sequence. If a mismatch is detected,
a CRC error has occurred and an Error Frame is generated. The message is repeated. The
receive error interrupt counter is incremented by one. An Interrupt will only be generated if the
error counter passes a threshold value. 23
23.6.5.2 Bit Stuffing Error
CAN Module
If, between the Start -Of-Frame and the CRC Delimiter, 6 consecutive bits with the same polarity
are detected, the bit-stuffing rule has been violated. A bit-stuffing error occurs and an error frame
is generated. The message is repeated. No interrupt will be generated upon this event.
If any type of error occurs during reception of a message, an error will be indicated by the IVRIF
bit (CiINTF<7>). This bit can be used (optionally with an interrupt) for autobaud detection with
the device in Listen Only mode. This error is not an indicator that any action needs to be taken,
but it does indicate that an error has occurred on the CAN bus.
A message has been successfully received and loaded into one of the receive buffers. This inter-
rupt is activated immediately after receiving the End-Of-Frame (EOF) field. Reading the RXnIF
flag will indicate which receive buffer caused the interrupt. Figure 23-12 depicts when the receive
buffer interrupt flag RXnIF will be set.
The Wake-up interrupt sequences are described in Section 23.13.1 “Operation in SLEEP
Mode”.
EOF
EOF
EOF
EOF
EOF
EOF
EOF
ACK DELIMITER
ACK SIST BIT
CRCDEL
CRC0
CRC1
CRC2
CRC3
CRC4
CRC5
CRC6
CRC7
CRC8 23
CRC9
CRC10
CAN Module
CRC11
CRC12
CRC13
CRC14
DLC0
DLC1
STUFF
DLC2
DLC3
RB0
IDE
RTR
ID0
ID1
ID2
ID3
ID4
ID5
ID6
ID7
ID8
ID9
ID10
SOF
Receive Buffer
Interrupt Flag
CAN bit
CAN bit
Names
Timing
Data
A receive error interrupt will be indicated by the ERRIF bit (CiINTF<5>). This bit shows that an
error condition occurred. The source of the error can be determined by checking the bits in the
CAN Interrupt Status Register CiINTF. The bits in this register are related to receive and transmit
errors. The following subsequences will show which flags are linked to the receive errors.
If any type of error occurred during reception of the last message, an error will be indicated by
the IVRIF bit (CiINTF<7>). The specific error that occurred is unknown. This bit can be used
(optionally with an interrupt) for autobaud detection with the device in Listen Only mode. This
error is not an indicator that any action needs to be taken, but an indicator that an error has
occurred on the CAN bus.
The RXnOVR bit (CiINTF<15>, CiINTF<14>) indicates that an overrun condition occurred for the
receive buffer. An overrun condition occurs when the Message Assembly Buffer (MAB) has
assembled a valid received message, the message is accepted through the acceptance filters,
however, the receive buffer associated with the filter is not clear of the previous message. The
overflow error interrupt will be set and the message is discarded. While in the overrun situation,
the module will stay synchronized with the CAN bus and is able to transmit and receive
messages.
The RXWAR bit (CiINTF<8>) indicates that the Receive Error Counter has reached the CPU
warning limit of 96. When RXWAR transitions from a ‘0’ to a ‘1’, it will cause the Error Interrupt
Flag ERRIF to become set. This bit cannot be manually cleared, as it should remain an indicator
that the Receive Error Counter has reached the CPU warning limit of 96. The RXWAR bit will
become clear automatically if the Receive Error Counter becomes less than or equal to 95. The
ERRIF bit can be manually cleared allowing the interrupt service routine to be exited without
affecting the RXWAR bit.
The RXEP bit (CiINTF<11>) indicates that the Receive Error Counter has exceeded the Error
Passive limit of 127 and the module has gone to Error Passive state. When the RXEP bit transi-
tions from a ‘0’ to a ‘1’, it will cause the error interrupt flag to become set. The RXEP bit cannot
be manually cleared, as it should remain an indicator that the bus is in Error State Passive. The
RXEP bit will become clear automatically if the Receive Error Counter becomes less than or
equal to 127. The ERRIF bit can be manually cleared allowing the interrupt service routine to be
exited without affecting the RXEP bit.
23.7 Transmission
This subsection describes how the CAN module is used to transmit CAN messages.
CAN Module
The CAN module has three Transmit Buffers. Each of the three buffers occupies 14 bytes of data.
Eight of the bytes are the maximum 8 bytes of the transmitted message. Five bytes hold the
standard and extended identifiers and other message arbitration information.
The last byte is a control byte associated with each message. The information in this byte
determines the conditions under which the message will be transmitted and indicates status of
the transmission of the message.
The TXnIF bit (CiINTF<2>, CiINTF<3> or CiINTF<4>) will be set and the TXREQ bit
(CiTXnCON<3>) will be clear, indicating that the message buffer has completed a transmission.
The CPU will then load the message buffer with the contents of the message to be sent. At a
minimum, the standard identifier register CiTXnSID must be loaded. If data bytes are present in
the message, the TXBnDm registers are loaded. If the message is to use extended identifiers,
the CiTXnEID register and the EID<5:0> bits (CiTXnDLC<15:10>) are loaded and the TXIDE bit
is set (CiTXnSID<0>).
Prior to sending the message, the user must initialize the TXnIE bit (CiINTE<2>, CiINTE<3> or
CiINTE<4>) to enable or disable an interrupt when the message is sent. The user must also
initialize the transmit priority. Figure 23-13 shows a block diagram of the Transmit Buffers.
MESSAGE
MESSAGE
MESSAGE
TXLARB
TXLARB
TXLARB
TXREQ
TXREQ
TXREQ
TXERR
TXERR
TXERR
TXABT
TXABT
TXABT
TXPRI
TXPRI
TXPRI
Message
Queue
Control
Transmit Byte Sequencer
CAN bus
CiTX
TXREQ 23
CAN Module
TXnIF
TXABT
1 2 3
1 - Processor sets TXREQ while module receiving/transmitting message. Module continues with CAN message.
2 - Processor clears TXREQ while module looking for 11 recessive bits.
Module aborts pending transmission, sets TXABT bit in 2 clocks.
3 - Another module takes the available transmit slot.
CAN bus
CiTX
ABAT
TXREQ
TXnIF
TXABT
1 2 3
1 - Processor sets TXREQ while module receiving/transmitting message. Module continues with CAN message.
2 - Processor sets ABAT while module looking for 11 recessive bits. Module clears TXREQ bits.
Module aborts pending transmission, sets TXABT bit.
3 - Another module takes the available transmit slot.
CAN bus
CiTX
TXREQ
TXnIF
TXABT
1 2 3 4
1 - Processor sets TXREQ while module receiving/transmitting message. Module continues with CAN message.
2 - Module detects 11 recessive bits. Module begins transmission of queued message.
3 - Processor clears TXREQ requesting message abort. Abort cannot be acknowledged.
4 - At successful completion of transmission, TXREQ bit remains clear and TXnIF bit set. TXABT remains clear.
CAN bus
CiTX
TXREQ
TXnIF
TXLARB
1 2 3 4 5
23
CAN Module
START
The message transmission sequence begins when
the device determines that the TXREQ for any of the
Transmit registers has been set.
No Are any
TXREQ
bits = 1
?
Yes
Is No Does
CAN bus available TXREQ = 0 No
to start transmission ABAT = 1
? ?
Yes Yes
Examine TXPRI<1:0> to
Determine Highest Priority Message
Was No
message transmitted Set
successfully? TXERR = 1
Yes
Set TXREQ = 0
Does Yes
TXLARB = 1? Arbitration lost during
transmission
Yes
Generate Is
Interrupt TXnIE = 1?
No
A message can also be
aborted if a message error or
Does lost arbitration condition
TXREQ = 0 Yes occurred during transmission.
Set or TXABT =1
TXBUFE = 1 ?
The TXnIE bit determines if an
interrupt should be generated when a No
message is successfully transmitted.
Abort Transmission:
Set TXABT = 1
END
The TXREQ bit can be cleared just when a message is starting transmission, with the intent of
aborting the message. If the message is not being transmitted, the TXABT bit will be set,
indicating that the Abort was successfully processed.
When the user clears the TXREQ bit and the TXABT bit is not set two cycles later, the message
has already begun transmission.
If the message is being transmitted, the abort is not immediately processed, at some point later,
the TXnIF interrupt flag or the TXABT bit is set. If transmission has begun the message will only
be aborted if either an error or a loss of arbitration occurs.
Setting the ABAT bit will abort all pending Transmit Buffers and has the function of clearing all of
the TXREQ bits for all buffers. The boundary conditions are the same as clearing the TXREQ bit.
The TXREQ bit can be cleared when a message is just about to successfully complete transmis-
sion. Even if the TXREQ bit is cleared by the Data bus a short time before it will be cleared by
the successful transmission of the message, the TXnIF flag will still be set due to the successful
transmission. 23
23.7.6.4 Setting TXABT bit as a Message Completes
CAN Module
The boundary conditions are the same as clearing the TXREQ bit.
The TXREQ bit can be cleared when a message is just about to be lost to arbitration or an error.
If the TXREQ signal falls before the loss of arbitration signal or error signal, the result will be like
clearing TXREQ during transmission. When the arbitration is lost or the error is set, the TXABT
bit will be set, as it will see that an error has occurred while transmitting, and that the TXREQ bit
was not set.
If the TXREQ bit falls after the arbitration signal has entered the block, the result will be like
clearing TXREQ during an inactive transmit time. The TXABT bit will be set.
The boundary conditions are the same as clearing the TXREQ bit.
CAN bus
CiTX
TXREQ
TXnIF
TXERR
1 2 3 4 5
In the Acknowledge field of a message, the transmitter checks if the Acknowledge Slot (which it
has sent out as a recessive bit) contains a dominant bit. If not, no other node has received the
frame correctly. An acknowledge error has occurred and the message has to be repeated. No
error frame is generated.
lf a transmitter detects a dominant bit in one of the four segments including End-Of-Frame,
lnterframe Space, Acknowledge Delimiter or CRC Delimiter; then a form error has occurred and
an error frame is generated. The message is repeated.
A bit error occurs if a transmitter sends a dominant bit and detects a recessive bit. In the case
where the transmitter sends a recessive bit and a dominant bit is detected during the Arbitration
field and the Acknowledge Slot, no bit error is generated because normal arbitration is occurring.
CAN Module
be broken up into two groups:
• Transmission interrupts
• Transmission error interrupts
At least one of the three transmit buffers is empty (not scheduled) and can be loaded to schedule
a message for transmission. Reading the TXnIF flags in the CiINTF register will indicate which
transmit buffer is available and caused the interrupt.
A transmission error interrupt will be indicated by the ERRIF flag. This flag shows that an error
condition occurred. The source of the error can be determined by checking the error flags in the
CAN Interrupt Status register CiINTF. The flags in this register are related to receive and transmit
errors.
The TXWAR bit (CiINTF<10>) indicates that the Transmit Error Counter has reached the CPU
warning limit of 96. When this bit transitions from a ‘0’ to a ‘1’, it will cause the error interrupt flag
to become set. The TXWAR bit cannot be manually cleared, as it should remain as an indicator
that the Transmit Error Counter has reached the CPU warning limit of 96. The TXWAR bit will
become clear automatically if the Transmit Error Counter becomes less than or equal to 95. The
ERRIF flag can be manually cleared allowing the interrupt service routine to be exited without
affecting the TXWAR bit.
The TXEP bit (CiINTF<12>) indicates that the Transmit Error Counter has exceeded the Error
Passive limit of 127 and the module has gone to Error Passive state. When this bit transitions
froma ‘0’ to a ‘1’, it will cause the error interrupt flag to become set. The TXEP bit cannot be
manually cleared, as it should remain as an indicator that the bus is in Error Passive state. The
TXEP bit will become clear automatically if the Transmit Error Counter becomes less than or
equal to 127. The ERRIF flag can be manually cleared allowing the interrupt service routine to
be exited without affecting the TXEP bit.
The TXBO bit (CiINTF<13>) indicates that the Transmit Error Counter has exceeded 255 and the
module has gone to bus off state. When this bit transitions from a ‘0’ to a ‘1’, it will cause the error
interrupt flag to become set. The TXBO bit cannot be manually cleared, as it should remain as
an indicator that the bus is off. The ERRIF flag can be manually cleared allowing the interrupt
service routine to be exited without affecting the TXBO bit.
RESET
Error
RERRCNT > 127 or Active
TERRCNT > 127
128 occurrences of
11 consecutive 23
“recessive” bits
RERRCNT < 127 or
CAN Module
TERRCNT < 127
Error
Passive
Bus
Off
Input Signal
Sample Point
TQ
TQ = 2 • (BRP + 1) • TCAN
TCY
TQ = 2 • (BRP + 1) • = 2 X 2 X (1/32X106) = 125ns
4
CAN Module
1. Select number of TQ clocks per bit time (e.g., K=16).
2. Calculate TQ from baud rate:
3
1 ⁄ ( BaudRate ) 1 ⁄ 125 ×10
TQ = -------------------------------------- = ---------------------------- = 500ns
K 16
3. Calculate BRP<5:0>:
TQ = 2 • (BRP + 1) • TCAN
BRP = ( 2T Q ⁄ T CY ) – 1
–9
2 ( 500 ×10 )
= ------------------------------
6
-–1
1 ⁄ ( 5 ×10 )
= 4
The frequencies of the oscillators in the different nodes must be coordinated in order to provide
a system-wide specified time quantum. This means that all oscillators must have a TOSC that is
a integral divisor of TQ.
23.9.6 Synchronization
To compensate for phase shifts between the oscillator frequencies of the different bus stations,
each CAN controller must be able to synchronize to the relevant signal edge of the incoming
signal. When an edge in the transmitted data is detected, the logic will compare the location of
the edge to the expected time (Synchronous Segment). The circuit will then adjust the values of
Phase1 Segment and Phase2 Segment. There are 2 mechanisms used to synchronize.
Hard Synchronization is only done whenever there is a “recessive” to “dominant” edge during bus
Idle, indicating the start of a message. After hard synchronization, the bit time counters are
restarted with Synchronous Segment. Hard synchronization forces the edge which has caused
the hard synchronization to lie within the synchronization segment of the restarted bit time.
Due to the rules of synchronization, if a hard synchronization is done, there will not be a
re-synchronization within that bit time.
23.9.6.2 Re-synchronization
CAN Module
Figure 23-22: Lengthening a Bit Period
Input Signal
TQ
Input Signal
TQ
000 ERR•WAK•TX0•TX1•TX2•RX0•RX1
001 ERR
100 ERR•TX0
011 ERR•TX0•TX1
010 ERR•TX0•TX1•TX2
110 ERR•TX0•TX1•TX2•RX0
101 ERR•TX0•TX1•TX2•RX0•RX1
23
111 ERR•TX0•TX1•TX2•RX0•RX1•WAK
CAN Module
Legend: ERR = ERRIF • ERRIE
TX0 = TX0IF • TX0IE
TX1 = TX1IF • TX1IE
TX2 = TX2IF • TX2IE
RX0 = RX0IF • RX0IE
RX1 = RX1IF • RX1IE
WAK = WAKIF • WAKIE
23.11 Time-stamping
The CAN module will generate a signal that can be sent to a timer capture input whenever a valid
frame has been accepted. Because the CAN specification defines a frame to be valid if no errors
occurred before the EOF field has been transmitted successfully, the timer signal will be
generated right after the EOF. A pulse of one bit time is generated.
Time-stamping is enabled by the TSTAMP control bit (CiCTRL<15>). The capture input that is
used for time-stamping depends on the device variant. Refer to the specific device data sheet for
more information.
OSC1
TOST
CAN bus
SLEEP
WAKIF
WAKIE
Processor in
SLEEP
CAN Module
1 2
Disabled
3 4 5
23
CAN Module
1 - Processor requests and receives Module Disable mode. Wake-up interrupt enabled.
2 - Processor executes SLEEP (PWRSAV #0) instruction.
3 - SOF of message wakes up processor. Oscillator start time begins. CAN message lost. WAKIF bit set.
4 - Processor completes oscillator start time. Processor resumes program or interrupt, based on GIE bits.
Processor requests Normal Operating mode. Module waits for 11 recessive bits before
accepting CAN bus activity. CAN message lost.
5 - Module detects 11 recessive bits. Module will begin to receive messages and transmit any pending messages.
If two or more bus nodes start their transmission at the same time (“Multiple Access”), collision
of the messages is avoided by bitwise arbitration (“Collision Detection/Non-Destructive
Arbitration” together with the “Wired-AND” mechanism, “dominant” bits override “recessive” bits).
Each node sends the bits of its message identifier (MSb first) and monitors the bus level. A node
that sends a recessive identifier bit but reads back a dominant one loses bus arbitration and
switches to Receive mode. This condition occurs when the message identifier of a competing
node has a lower binary value (dominant state = logic 0) and therefore, the competing node is
sending a message with a higher priority. In this way, the bus node with the highest priority
message wins arbitration without losing time by having to repeat the message. All other nodes
automatically try to repeat their transmission once the bus returns to the IDLE state. It is not
permitted for different nodes to send messages with the same identifier, as arbitration could fail,
leading to collisions and errors later in the message.
The original CAN specifications (Versions 1.0, 1.2 and 2.0A) defined the message identifier as
having a length of 11 bits giving a possible 2048 message identifiers. The specification has since
been updated (to version 2.0B) to remove this limitation. CAN specification Version 2.0B allows
message identifier lengths of 11 and/or 29 bits to be used (an identifier length of 29 bits allows
over 536 million message identifiers). Version 2.0B CAN is also referred to as “Extended CAN”;
and Versions 1.0, 1.2 and 2.0A) are referred to as “Standard CAN”.
CAN Module
CAN modules specified by CAN V2.0A are only able to transmit and receive standard frames
according to the Standard CAN protocol. Messages using the 29-bit identifier cause errors. If a
device is specified by CAN V2.0B, there is one more distinction. Modules named “Part B Passive”
can only transmit and receive standard frames but tolerate extended frames without generating
error frames. “Part B Active” devices are able to transmit and receive both standard and
extended frames.
The LLC sub layer is concerned with Message Filtering, Overload Notification and Error
Recovery Management. The scope of the LLC sub layer is:
• To provide services for data transfer and for remote data request.
• To decide which messages received by the LLC sub layer are actually to be accepted.
• To provide means for error recovery management and overload notifications.
The MAC sub layer represents the kernel of the CAN protocol. The MAC sub layer defines the
transfer protocol, (i.e., controlling the Framing, Performing Arbitration, Error Checking, Error
Signalling and Fault Confinement). It presents messages received from the LLC sub layer and
accepts messages to be transmitted to the LLC sub layer. Within the MAC sub layer is where it’s
decided whether the bus is free for starting a new transmission, or whether a reception is just
starting. The MAC sub layer is supervised by a management entity called Fault Confinement
which is a self-checking mechanism for distinguishing short disturbances from permanent
failures. Also, some general features of the bit timing are regarded as part of the MAC sub layer.
The physical layer defines the actual transfer of the bits between the different nodes with respect
to all electrical properties. The PLS sub layer defines how signals are actually transmitted and
therefore deals with the description of Bit Timing, Bit Encoding and Synchronization.
The lower levels of the protocol are implemented in driver/receiver chips and the actual interface
such as twisted pair wiring or optical fiber, etc. Within one network, the physical layer has to be
the same for all nodes. The driver/receiver characteristics of the physical layer are not defined in
the CAN specification so as to allow transmission medium and signal level implementations to
be optimized for their application. The most common example of the physical transmission
medium is defined in Road Vehicles ISO11898, a multiplex wiring specification.
Application
Presentation
Session
Transport
Network
Supervisor
LLC (Logical Link Control)
Acceptance Filtering
Overload Notification
Recovery Management
CAN Module
Serialization/Deserialization
Physical Layer
Note: Please visit the Microchip web site (www.microchip.com) for additional Application
Notes and code examples for the dsPIC30F Family of devices.
23
CAN Module
NOTES: