Oscillograph detection method based on CAN bus

stm32The can bus is on APB1, the main frequency of stm32f10x is 72Mhz, the peripheral clock of can is 36Mhz, the main frequency of stm32f2xx is 120Mhz, and the peripheral clock of can is 30Mhz.

STM32 APB1Distinguish from APB2:

APB2Responsible for AD, I/O, advanced TIM, serial port 1.

APB1Responsible for DA, USB, SPI, I2C, CAN, serial port 2345, common TIM

 

canBus electrical characteristics

 

It’s not easy to do the data on the CAN bus from the car.

So I first use the oscilloscope (the type of oscilloscope I use is TDS 220) to find the interface of the CAN bus on the car, and then measure the baud rate of the can bus. The steps to measure the baud rate are as follows:

1、Two interfaces (grounding and probe) of the oscilloscope are connected to two lines (CAN_H and CAN_L) of the CAN bus respectively.
Note that if a 120 ohm load resistor is needed on the CAN line, otherwise the waveform is an irregular square wave.
After loading, the square wave is regular.

2、At this point, if there is data on the can line, the square wave will appear on the oscillograph as shown in Figure 1. (use the RUN/STOP button of the oscilloscope to capture the waveform).

                                                     Figure 1

2、But at this time, because the oscilloscope displays too many data, it is not possible to read the cycle of a single pulse.
Therefore, we need to adjust the cycle represented by the X axis of the oscilloscope (adjusting the SEC/DIV knob).
Then use the RUN/STOP button to re capture the waveform and get the waveform shown in Figure 2.

                                                       Figure 2

3、Finally, amplify the smaller pulse width in Figure 2 (adjust SEC / DIV) again until Figure 3 shows that each cell represents one US
You can see that this pulse span is 8us

                                                      Figure 3

So the final baud rate of the CAN bus is 1s/8us=125K

 

 

 

 

In the vehicle electronic network, the CAN bus is an important protocol. It has a bit rate of up to 1 megabit and provides a simple microprocessor network, which requires a dedicated CAN bus chip called a CAN controller called a CAN controller.

CANThe data transmission message is the data frame. The data frame allows a relatively long ID, so it is called an extensible frame.

For some applications, but not for cars, it’s a remote frame. Remote frames allow a node to respond to a specific ID.

CANThe functions are very complete. This means that it can detect not only many errors, but also automated transmission or node shutdown.

CANA bit stream is used to pass the receiver to the transmitter. In order to be suitable for specific bit order, CAN must use bit filling. Bit filling is difficult to decode CAN waveform on traditional oscilloscope.

CANIt is a data link layer. There are three physical layers that are being used to transmit electric signals to CAN.

In some places where CAN bus is used, it may be more appropriate to use FlexRay or LIN.

CANDetailed instructions of the bus:PDFcan2spec.pdf

CAN Bus Frame
A data frame for CAN bus

CANBus data frame

CANBus data frames operate on CAN. The whole process of CAN is essentially sending data between network controllers, which requires data frames to achieve this function.

The data frame starts with a single SOF (Qi Shizheng) bit followed by the CAN identifier. The CAN identifier is used to identify the message and the next node message. Identifiers can have 11 bits or 29 bits. This is mainly determined by the state of reserved bits.

SOF and CAN ID
CANThe data frame starts with a SOF bit followed by a ID bit.

After the CAN identifier, there is a data segment, and the data segment starts with a data length. The CAN data frame can have 0 to 8 bytes, so that it uses 4 bit encoding length. The data byte directly follows the data length.

CAN DLC and Data Bytes
In CAN frames, data bytes follow data length (DLC).

Following the data is CRC. CRC is based on the first part of the CAN frame in the receiver and transmitter. If the calculated results match the results presented by the receiver, it is correct to receive data.

CAN CRC and ACK
CAN The CRC checks the integrity of data, while ack means receiving from another node.

Following the CRC is the Ack field, which is set on all other network nodes that receive frames correctly.  
AckAfter the bit, there is a static time, which is called the frame space terminator immediately following a minimum interpolated frame space.

 

ImageA CAN data frame picture

Extended data frames

The extensible identifier CAN frame uses 29 bits for identifying the purpose, not the 11 bits of the standard CAN frame. Because this extra ID space adds 20 bits (18 IDs and two reserved bits), it is usually not used in networks that want the highest performance.

In the J1939 and GMLAN protocols, the larger ID is divided into different parts, and each part has its meaning. For example, the lowest 8 ID bits for J1939 and GMLAN indicate the source address of a byte.

Extended ID
The single line CAN extension ID is 29 bits long (not yet counted as buffer bit). Many system designers do not use this ID length.
Because it requires higher fees.

CANBus remote data frame

CANBus remote frames are optional frames, which are used to request data. Remote frames do not contain data segments, even if the length of data bits is greater than 0. You can judge whether a frame is a remote frame (RTR=1) from the state of the RTR bit. Remote frames are usually not used in automotive applications.

CAN Remote Frame
A remote frame is displayed in this CAN L waveform.

CANBus error

 

 

 

Please look at the picture >

CANBus bit filling

CANWaveform is a series of bits. Since there is no shared clock between CAN bus nodes, there must be a way for all nodes to get clock information from the waveform. Therefore, the receiver uses CAN waveform conversion to synchronize the transmitter and receiver.

To ensure adequate conversion, the CAN bus performs bit fill function. Bits fill in 5 consecutive bits and insert an extra bit stream. Because the occurrence of fill bits depends on the capacity of the message sequence, the length of the CAN frame should be changed according to the data bits in the frame. These extraFill bits are automatically thrown away by the receiver, so they are never touched in CAN node applications.

CAN Stuff Bits
The fill bit is highlighted in yellow and added to a CAN message. This message has 13 additional bits.

CANBus physical layer

CANThe protocol describes how 1s and 0s are used in communications. The CAN protocol does not introduce electrical methods for transmitting 1s and 0s signals.  

The most popular physical layer is known as the two-layer physical layer. The physical layer uses dual line CAN H and CAN L. These lines are uploaded to 1 or 0 in different voltage directions (corresponding to different signal transmissions).  

Two other physical layers are introduced for specific vehicle low speed applications. They are single line CAN and low speed fault tolerant CAN. If one line is broken. Low speed fault tolerant CAN bus will provide fault tolerance information.

Single line CAN

Single line CAN is a physical layer, which is generated by ordinary engines. It allows CAN to communicate with a single line at low bit rates (such as 33.3Kbps). At the same time, flash programming allows a high-speed mode. Finally, although many CAN transceivers only provide 1 or0, but the single line can still provide a third state called high voltage mode. This mode enables the power management of CAN nodes to be selective.

Single Wire CAN Voltages
These are two different single line CAN frames. One is sent in high voltage mode and the other is normal voltage.

Leave a Reply

Your email address will not be published. Required fields are marked *