After a CAN node is connected to the bus, all CAN data frames on the bus can be received without filtering disabled. If you only need to receive a data frame with a fixed range of IDs, you can configure the mask code and acceptance code to filter the data frame.When the data frame is transmitted on the CAN bus, the CAN node uses an acceptance filter to compare whether the ID of the data frame on the bus is consistent with the ID of the node, and if the ID is consistent, the CAN controller allows the received information to be stored in the corresponding registerid, the data frame will be discarded to reduce the workload of the CAN controller. The acceptance filter is composed of an acceptance register (ACR) and an acceptance shield register (AMR). The user configures the acceptance shield register and the acceptance ** register, and then obtains the corresponding mask code and acceptance code to filter the CAN data frame. In this paper, the SJA1000 is used as an example, and its filtering methods are divided into two types: single filter and double filter. Controlled by the mode register AFM bit, single filter at AFM = 1;afm=0 is double filtering.
In the double filter mode, two acceptance filters are defined, and as long as the received data frame passes through one of the acceptance filters, it is considered a valid frame, and can be received normally and stored in the register. ACR0, ACR1, AMR0 and AMR1 form the first acceptance filter, and ACR2 and ACR3 form the second acceptance filter. For example, the first two bytes of the ID segment of the data frame, that is, the upper 16 bits of the 29-bit ID, participate in the filtering. The control IDs of ACR0 and ACR1 are NO13-no.28, ACR2 and ACR3 also control the ID bit as No13-no.28, as shown in Table 1. This means that the CAN extends the frame ID bit No13-no.28: These 16 bits must be consistent with one of these two sets of acceptances in order to be received by the node and stored in the receive bufferOtherwise, the data frame is discarded, which results in two filters.
Table 1 Mapping of AMR, ACR, and control ID bits.
In the single-filter mode, the ACR bits corresponding to all bits with an AMR of "0" and the bits corresponding to the single-filter data must be consistent to be considered to have passed the acceptance filter, as shown in Table 2. When receiving a CAN standard frame, the 11-bit ID, RTR bit, and the first 16 bits of the data segment all participate in filteringWhen receiving a CAN extended frame, the 29-bit ID and RTR bits are involved in filtering, as shown in Figure 1.
Table 2 Mapping tables of AMR, ACR, and filtered IDs.
Figure 1 Schematic diagram of the frame formats of CAN standard frames and CAN extended frames.
Our isolated SPI UART to CAN chip CSM330A does not use single or double filter for reception filtering. The acceptance filter of the CSM330A is composed of 1 acceptance shield register and 6 acceptance ** registers, and users can "manage" 6 groups of acceptance codes by configuring a set of shield codes. When a bit of the mask code is 1, the acceptance code corresponding to the bit will be "enabled", and the "acceptance code" of the enabled "acceptance code" will be the same as the "frame ID" of the CAN frame to be received by the product, and the CAN frame will be received to the receiving buffer. When the bit value of the mask code is 0, the acceptance code does not work, and the frame of the corresponding bit can be received as any value, as shown in Table 3.
Table 3 Truth values of filtering and masking codes.
CSM330A is suitable for industrial communications, battery testing, charging piles, rail transit, building automation and other fields. The CSM330A protocol conversion chip is used in the application scheme of driver behavior monitoring in smart cars, as shown in Figure 2. ZLG mainly provides modular solutions for DMS industry customers, such as main control, power supply, and communication protection. The main control is the Cortex-A35 M1808 AI core board, which is equipped with self-developed image sensing technology and an in-vehicle behavior detection system solution. It can realize the functions of driver identification, alarm and reminder for abnormal operation of driver.
Figure 2 Driver behavior detection application scheme.