Background of the problem
I need to write a new motor driver, using CAN communication. The driver is relatively simple and was written quickly. When I tested a motor by myself, there was no problem, and the forward and reverse rotation tests were all normal. I thought things would go smoothly, but when I tested two motors, I found serious problems, and the left motor often did not install or the right motor did not rotate.
Steps to solve the problem
Option One:
1. When encountering this kind of problem, we usually add a delay, thinking that it may be sent too quickly, and there may be a problem with the timing, but our system is a real-time system and the delay cannot be too long.
2. After testing, it was found that adding a delay may reduce the probability of this problem, but it cannot solve the problem. In the end, the car still cannot operate normally. There is no way this solution will work.
analyze:
Since adding a delay doesn't work, we can only find out why the motor is not installed. After using CAN to USB to capture the data, we found that the motor does not rotate because of frame loss. Each motor needs 2 frames of data to send data, and two motors have 4 frames of data. But only 3 frames of data can be captured. One frame of data is lost. Then this may be because the CAN sending mailbox is not enough, resulting in frame loss.
background knowledge:
send
3 email addresses
The priority of sending messages can be configured by software
Record the timestamp of when SOF is sent
take over
2 receive FIFOs with 3 levels of depth
14 variable width filter banks – shared by the entire CAN
Identifier List
FIFO overflow handling is configurable
Record the timestamp of receiving SOF
Therefore, my next analysis is to check the number of free registers in the CAN mailbox to see if it is because when 4 frames of data are sent continuously, the CAN free mailbox is not enough.
Therefore, before each transmission, I check bits 26, 27, and 28 of this register to count the number of available mailboxes.
Option II:
Before sending, we count the number of available mailboxes. We will only send new data if there are mailboxes.
result:
The result was unexpected. Every time I sent a message, the number of mailboxes displayed was always 3, which means there was no shortage of mailboxes. Solution 2 was not feasible.
Continue analysis:
It was found that when running, this bit would often be set to 1, not because of insufficient mailboxes to lose data, but because of arbitration to lose data.
Further verification:
It is found that this register always replies to mailbox 0, so it is not a problem of insufficient mailboxes. It is completely sufficient to send 4 frames of data every 50ms.
third solution:
Because the ID of the sent data is larger than the ID replied by the slave, the data frame arbitration may be lost when the CAN is preempted because of the larger ID.
Therefore, the automatic resend function of CAN is enabled.
Using the hal library is just one sentence:
g_sCAN_Handler[dwDevice].Init.NART = DISABLE; // Enable automatic retransmission
Results Problem, Perfect Solution
Previous article:STM32 hal library analysis uart
Next article:LIN bus development: STM32F0 TJA1020
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- DSP Learning (1) Introduction to Digital Signal Processors (DSPs)
- 【Portable Environmental Status Detector】RTC Electronic Clock
- Espressif's ESP32-C3 is an extremely low-power SoC equipped with a RISC-V 32-bit single-core processor
- [Gizwits Gokit3 Review] + AirLink configuration (Arduino)
- Node voltage calculation
- Showing goods + artificial intelligence first board dog bone AI
- [TI mmWave Radar Evaluation]_5_AWR1843BOOST Corridor Ranging Corner Reflector Test
- Operational amplifiers in series can achieve high precision and high output power at the same time
- CC2640 BLE Bluetooth wireless module low power consumption
- pyESP32 board design draft and BOM list