This routine implements all four different mask setting methods.Users can refer to these routines to implement some application scenarios.Please note that this routine is for reference only.When posting this routine, I only did some limited tests, and I don't make sure that there are no problems. If you find it, please leave a message and I will revise it in time.
When the program was flashed into the S32K142EVB, the Blue Led will toggles every 500ms, this Led shows that the program is running on well condictions. If a message was received by S32K142EVB from external CAN bus, the Green Led will toggle,at the same time, the S32K142EVB will sent a message to CAN Bus which have the same data with the message received,and the ID is 0x02.At the last,the Red Led will toggle when a CAN error is occurd.
1.FlexCAN Mask Setting Overview
S32K1XX FlexCAN support Frame mask function ,as you can see the FlexCAN mask can be set to Global Mask or Individual Mask,and user can choose to use FIFO or MB to receive message,but only MB can be used for sending messages.and one more thing you should be care is that the FIFO can not be used for CAN FD,this is because the FIFO data filed only support 8 bit datafiled.
If you use MB14 or MB15, have to set the mask of these tow MBs separately,and you can take a look at the two functions in the below.
->FLEXCAN_DRV_SetRxMb14Mask();
->FLEXCAN_DRV_SetRxMb15Mask();
2.Hardware Needs.
1.S32k142EVB,(or own made board which can support CAN communications.)
2.CAN TOOL's which used for send or receive messages from CAN Bus on your computer.
If you don't have such tools ,you can use another board which can replace the CAN tools to send or receive CAN messages.
3.S32K142EVB should be powered by external 12V DC, and don't forget to connect the J107 to 1-2.
3.Software Needs.
1.This demo build on S32 Design Studio for ARM V2.2
2.The SDK version is SDK_S32K1XX_15
4.FlexCAN_RX_MB_Mask_Setting
4.1.Set the Mask Type to Global Mask Type.
In this case, we can only receive the messages which ID from 0x300~0x37F and 0x400~0x47F.
If you try to sent the messages with other ID's, the S32K142EVB will not have any reponse!
4.2.Set the Mask Type to Individual Mask Type.
In this routine,we can only receive frames with IDs in the range of 0x400~0x47F.
5.FlexCAN_RX_FIFO_Mask_Setting
5.1.Set the Mask Type to Global Mask Type.
In this routine,we can only receive frames with IDs in the range of
0x10~0x17, 0x20~0x27,0x30~0x37,0x40~0x47,
0x50~0x57,0x60~0x67,0x70~0x77,0x80~0x87.
5.2.Set the Mask Type to Individual Mask Type.
In this routine, we can only receive frames with IDs in the range of
0x10~0x17,0x20~0x27,0x30~0x37,0x40~0x47,
0x50~0x57,0x60~0x67,0x70~0x77,0x80~0x87.
End
If you need to use CAN FD, please note that FIFO cannot be used. Regarding FIFO, it has three filtering formats, you can refer to the following chapters in the data sheet for details.
S32K-RM Rev 13.
Chapter:55.4.2.15 Rx FIFO Global Mask register (RXFGMASK)
Chapter:55.4.6 Rx FIFO structure
View full article