目 录
FlexCAN简介
FlexCAN初始化
FlexCAN发送报文
FlexCAN接收报文
FlexCAN中断
CAN错误
1. FlexCAN简介
CAN网络拓扑
CAN总线
CAN收发器
TJA1050/1、MCP2551
CAN控制器
独立控制器SJA1000、MCP2515
Bosch M_CAN、X_CAN
NXP FlexCAN
FlexCAN拓扑
Bus Interface Unit (BIU)
Message Buffers(MBs)
Controller Host Interface (CHI)
Protocol Engine (PE)
FlexCAN Memory Map
2. FlexCAN初始化
FlexCAN 工作模式
FlexCAN初始化
CAN波特率设置
CAN_CTRL1(PRESDIV 8bits、PROPSEG 3bits、PSEG1 3bits、PSEG2 3bits、RJW 2bits)
CAN_CBT(BTF 1bit、EPRESDIV 10bits、EPROPSEG 6bits、EPSEG1 5bits、EPSEG2 5bits、ERJW 5bits)
CAN_FDCBT(PRESDIV 10bits、FPROPSEG 5bits、FPSEG1 3bits、FPSEG2 3bits、FRJW 3bits)
FlexCAN Message Buffer Structure
0x80~0x87F 128个 128-bit message buffers(MBs)
CS、ID、DATA(8、16、32、64)
CAN_FDCTRL.MBDSR0/1/2/3
3. FlexCAN发送报文
FlexCAN发送MB配置
FlexCAN发送报文类型:
标准帧(Classical CAN/CAN FD)
扩展帧(Classical CAN/CAN FD)
远程帧(Classical CAN)
FlexCAN Arbitration Process
发送优先级设置:
CAN_CTRL1. LBUF :Lowest Buffer Transmitted First
CAN_MCR.LPRIOEN:Local Priority Enable
中断使能/标志位:
CAN_IMASK1/CAN_IFLAG1:MB0~MB31
CAN_IMASK2/ CAN_IFLAG2:MB32~MB63
CAN_IMASK3/ CAN_IFLAG3:MB64~MB95
CAN_IMASK4/ CAN_IFLAG4:MB96~MB127
FlexCAN 发送实例
4. FlexCAN接收报文
FlexCAN接收报文
MB接收配置 - Rx Mask
MB接收配置 - MB
FlexCAN Rx FIFO Structure
0x80~0xDC(MB0~MB5) Rx FIFO engine
0x80~0x8C output
0x90~0xDC internal use
0xE0~0x2DC (MB6~MB37) ID filter table
8~128 table elements
CAN_MCR.RFEN、 CAN_CTRL2.RFFN、CAN_MCR.IDAM
CAN_MCR.IDAM: D Acceptance Mode
00: Format A
01: Format B
10: Format C
11: Format D – All frames rejected
IDHIT、CAN_RXFIR.IDHIT
CAN_IMASK1
CAN_IFLAG1
BUF0I: Empty the FIFO
BUF1I~ BUF4I : Reserved
BUF5I: Frames available in Rx FIFO
BUF6I: Rx FIFO Warning
BUF7I: Rx FIFO Overflow
Rx FIFO接收配置 - Rx Mask
FlexCAN Rx FIFO with DMA
CAN_IFLAG1
BUF0I~ BUF4I : Unused
BUF5I: Frames available in Rx FIFO
BUF6I~BUF7I: Unused
FlexCAN Matching Process
Matching优先级:
CAN_CTRL2. MRP: Mailboxes Reception Priority
1: Matching starts from mailboxes and continues on Rx FIFO
0: Matching starts from Rx FIFO and continues on mailboxes
Matching starts from the lowest number toward the higher ones
FlexCAN 接收实例
5. FlexCAN中断
CAN错误
6. CAN错误
CAN网络拓扑
Error counters:
CAN_ECR.TXERRCNT
CAN_ECR.RXERRCNT
Error flags:
CAN_ESR1.TXWRN(CAN_ECR.TXERRCNT>=96)
CAN_ESR1.RXWRN(CAN_ECR.RXERRCNT>=96)
CAN_ESR1.BIT1ERR/BIT0ERR
CAN_ESR1.ACKERR
CAN_ESR1.CRCERR
CAN_ESR1.FRMERR
CAN_ESR1.STFERR