STM32 CAN---Error Management Analysis

Publisher:电子科技爱好者Latest update time:2015-11-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Several important concepts

       According to ISO11898, there are several important CAN-related definitions:

  • Fault confinement

CAN nodes shall be able to distinguish short disturbances from permanent failures. Defective transmitting nodes shall be switched off. Switched off means a node is logically disconnected from the bus, so that it can neither send nor receive any frames.

CAN nodes can distinguish between normal errors and permanent faults. A faulty transmitting node will switch to the offline state. Offline means logically disconnected from the bus and can neither send nor receive.

  • Error-active

An error-active node shall normally take part in bus communication and send an active error flag when an error has been detected. The active error flag shall consist of six (6) consecutive dominant bits and shall violate the rule of bit stuffing and all fixed formats appearing in a regular frame.

A node in the active error state can participate in the transmission and reception of bus communications normally and will send an error flag when an error is detected. The error flag consists of 6 consecutive display bits (these 6 consecutive display bits are different from the conventional fill bits and other frame fixed formats. Because of this, the hardware can easily distinguish them).

  • Error-passive

An error-passive node shall not send an active error flag. It takes part in bus communication, but when an error has been detected a passive error flag shall be sent. The passive error flag shall consist of six (6) consecutive recessive bits. After transmission, an error-passive node shall wait some additional time before initiating a further transmission.

A node in the passive error state cannot send an active error flag. It can participate in normal communication, but when an error is detected, it sends a passive error flag. The passive error flag consists of 6 consecutive recessive bits. After the transmission is completed, the node in the passive error state needs to wait some extra time before sending again next time.

  • Bus-off

A node shall be in the bus-off state when it is switched off from the bus due to a request of FCE. In the bus-off state, a node shall neither send nor receive any frames. A node shall start the recovery from bus -off state only upon a user request.

Due to the error boundary rules, a node may be offline, when in this state, the node neither sends nor receives. When to recover from offline depends on when the user requests it.

2 Incorrectly defined rules in ISO 11898

2.1 Description

When it comes to error demarcation, a node must be in one of the following three error states, depending on the node's error count value:

  • Error-active
  • Error-passive
  • Bus-off

2.2 Error Count

The error counter will update the error count value when detecting the following events:

  • When a receiving node detects an error, the error counter will be increased by 1. There is one exception, that is, when a single-bit error is detected when sending an active error flag or an overload flag.
  • When a receiving node sends an error flag, the error counter is incremented by 8 when the first bit is detected as a dominant bit.
  • When an error flag is sent after a transmission, the error counter is incremented by 8, except for two cases: 1: When the sending node is in an active error state and detects an ACK error caused by the absence of a dominant bit in the ACK field, but no passive error flag is detected during transmission; 2: When the sending node sends an error flag, a padding bit error is detected during arbitration (these padding bits should originally be recessive, but the detection result is dominant). The above two abnormal error count values ​​remain unchanged.
  • When the sending node sends an active error flag or an overload flag, the error counter is incremented by 8 when a bit error is detected.
  • When the receiving node sends an active error flag or an overload flag, the error counter is incremented by 8 when a bit error is detected.
  • Any node shall tolerate 7 consecutive display bits when sending an active error flag, a passive error flag, or an overload flag. When 14 display bits are detected, or a passive error flag is followed by 8 display bits, or 8 consecutive dominant bits are detected followed by a passive error flag, all sending nodes increase their send error counter by 8, and all receiving nodes increase their receive error counter by 8.
  • After successfully sending a frame of message, the sending counter should be reduced by 1, unless it is currently 0.
  • After successfully receiving a frame of message, if the current receive counter value is greater than 1 and less than 127, the receive counter is reduced by 1; if the receive counter value is 0, it remains at 0; if it is greater than 127, the receive counter value should be set to a value between 119 and 127.

2.3 Transitions between active error state and passive error state

When the value of the send error counter or the receive error counter is greater than 127, the node changes to the passive error state.

When a node changes from an active error state to a passive error state, the node will send an active error flag.

When the values ​​of the send error counter and the receive error counter of the passive error node are both less than and equal to 127, it will change to the active error state again.

2.4 Offline Management

If the value of a node's send error counter exceeds 255, the node will be in offline state. A node in offline state will not have any impact on the bus. It will not send message frames, ACK, error frames, overload frames, etc. As for whether it will receive data on the bus, the implementation of this node is cancelled.

When a node in the offline state receives 128 connections with 11 recessive bits, it will become an active error state and set the send error counter and receive error counter to 0 at the same time.

Note: The specific implementation may not be exactly the same as described above. For example, in offline recovery, there is a switch in STM32 to set whether to automatically recover. If this function is disabled, then when the node in the offline state receives 128 connections and 11 consecutive recessive bits, it will not recover to the active error state.

Figure 1[page]

3 bxCAN implementation of STM32

3.1 bxCAN error status diagram

                                                                                 figure 2

3.2 Error Management

The error management described in the CAN protocol is completely implemented by hardware through the send error counter (TEC field in the CAN_ESR register) and the receive error counter (REC field in the CAN_ESR register), and its value increases or decreases according to the error situation. The software can read their values ​​to determine the stability of the CAN network. In addition, the CAN_ESR register provides detailed information on the current error status. By setting the CAN_IER register (such as the ERRIE bit), the software can flexibly control the generation of interrupts-when an error is detected.

3.3 Offline recovery

When TEC is equal to 255, bxCAN enters the offline state, and the BOFF bit of the CAN_ESR register is set to '1'. In the offline state, bxCAN cannot receive or send messages.

Depending on the setting of the ABOM bit in the CAN_MCR register, bxCAN can recover from the offline state (become an error-active state) automatically or at the request of the software. In both cases, bxCAN must wait for a recovery process described by the CAN standard (128 times 11 consecutive recessive bits are detected on the CAN RX pin).

If the ABOM bit is '1', the bxCAN will automatically start the recovery process after entering the offline state.
If the ABOM bit is '0', the software must first request the bxCAN to enter and then exit the initialization mode before the recovery process is started.

Note: In initialization mode, bxCAN does not monitor the state of the CAN RX pin, so the recovery process cannot be completed. In order to complete the recovery process, bxCAN must operate in normal mode.

4 CAN Error Status Register (CAN_ESR)

Address offset: 0x18
Reset value: 0x0000 0000

                                                                                       image 3

 

Position 31:24 REC[7:0]: Receive Error Counter
This is the implementation of the receive part of the fault definition mechanism of the CAN protocol. According to the CAN standard, when a reception error occurs, the counter is incremented by 1 or 8 depending on the error situation; and after each successful reception, the counter is decremented by 1, or its value is reduced to 120 - when the value of the counter is greater than 127. When the value of the counter exceeds 127, CAN enters the error passive state.
Position 23:16 TEC[7:0]: Transmit Error Counter
Similar to the above, this is the implementation of the send part of the fault definition mechanism of the CAN protocol.
Position 15:7 Reserved bit, forced to 0 by hardware.
Position 6:4 LEC[2:0]: Last error code
When an error is detected on the CAN bus, the hardware sets it to a value of 1 to 6 according to the error condition. When the message is correctly sent or received, the hardware clears it to '0'.
The hardware does not use error code 7, and the software can set this value so that the code update can be detected.
000: No error;
001: Bit fill error;
010: Format error;
011: Acknowledgement error;
100: Hidden bit error;
101: Explicit bit error;
110: CRC error;
111: Set by software.
Bit 3 Reserved bit, forced to 0 by hardware.
Bit 2 BOFF: Bus Off Flag
When entering the offline state, the hardware sets this position to 1. When the send error counter TEC overflows, that is, greater than 255, CAN enters the offline state.
Bit 1 EPVF: Error Passive Flag
When the number of errors reaches the error passive threshold, the hardware sets this position to 1.
(The value of the receive error counter or the transmit error counter is > 127).
Bit 0 EWGF: Error warning flag
When the number of errors reaches the warning threshold, the hardware sets this position to 1.
(The value of the receive error counter or the send error counter is ≥ 96).
 
正文结束
point

Keywords:STM32 Reference address:STM32 CAN---Error Management Analysis

Previous article:CAN error interrupt 1 in STM32
Next article:Detailed explanation of the use of STM32 CAN module

Recommended ReadingLatest update time:2024-11-16 19:45

STM32 usb_pwr.c file analysis
As you can tell from the file name usb_pwr.c, this file is related to power consumption and has many states: power on, power off, suspend, and resume. First of all, the USB power-on and power-off functions are defined. The USB power-on function is as follows: /**********************************************************
[Microcontroller]
STM32 memory distribution exploration
I encountered a very strange problem when running ucos. After running for a period of time, it would inexplicably enter the hardfault function, causing the system to crash. Later, based on stack debugging, it was found that the functions called each time were different, which was very puzzling. Through the map file, i
[Microcontroller]
STM32 learning: timer time calculation
Assuming the system clock is 72Mhz, TIM1 is derived from PCLK2 (72MHz), and TIM2-7 are derived from PCLK1 The key is to set the clock pre-division number and the value of the automatic reload register cycle /*An update event occurs every 1 second (entering the interrupt service routine). RCC- CFGR |= (uint32_t)RCC_CFG
[Microcontroller]
STM32 usb_endp.c and usb_istr.c file analysis
Sometimes I always wonder, what is the best way to learn? Just like learning USB, is it enough to just learn how to apply it, or do I have to go deep into the protocol content and the underlying driver? I often tell others that I know something, but in fact I only know a little bit, and I only know some applications t
[Microcontroller]
8 configuration modes of STM32 GPIO port
1. The input and output pins of STM32 have the following 8 possible configurations (4 inputs + 2 outputs + 2 multiplexed outputs):         ① Floating input_IN_FLOATING         ② With pull-up input_IPU          ③ With pull-down input_IPD                            ④ Analog input_AIN         ⑤ Open dra
[Microcontroller]
Problems encountered when using STLINK to burn external FLASH in STM32
Since the project requires a large number of image fonts and audio files, NOR flash and NAND flash are plugged in. The burning algorithm STLDR (which contains several sections of code running in SRAM) is needed. Several problems were encountered during debugging, all of which were caused by carelessness, so I wrote th
[Microcontroller]
dsPIC30F6014 controls DS18B20 temperature + CAN bus sending program
dsPIC30F6014 controls DS18B20 temperature + CAN bus sending program // 1. DS18B20 collects temperature regularly // 2. The temperature collection time interval is controlled by T1 timer // 3. The collected temperature is sent to another host for processing via the CAN bus   #include p30f6014.h //dsPIC30F6014 standar
[Microcontroller]
Interface Implementation between TMS320C6416 and CAN Controller
Abstract: The interface timing between the digital signal processor TMS320C6416 and the CAN controller SJAl000 is analyzed . The interface circuit between the DSP digital signal processor based on the complex programmable logic device EPM7512 and the CAN controller is given, and the detailed software and h
[Industrial Control]
Interface Implementation between TMS320C6416 and CAN Controller
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号