The Design of Parameter Test System for Lithium Battery of Electric Vehicle Based on STM32 Single-Chip Microcomputer ()

1. Introduction
In modern society, there is an increasing demand for energy conservation and emission reduction, and people are paying more and more attention to environmental protection and green energy applications. Excessive use of traditional fuel vehicles has led to the depletion of petroleum resources, and exhaust emissions have aggravated the greenhouse effect and increased environmental pollution. As an energy-saving and environmentally friendly alternative to traditional fuel vehicles, electric vehicles have attracted much attention. As the energy source of electric vehicles, batteries can achieve zero emissions and high energy utilization [1]. However, the use of lithium batteries has always been a safety hazard, so real-time data detection of lithium batteries has become extremely important.
The development and research of the lithium battery parameter detection system abroad started earlier than the domestic one [2]. In foreign universities and research institutions, a large number of studies have been conducted on some functions in the lithium battery parameter detection system, such as the calculation of current and voltage. Especially in recent years, some large automobile manufacturers and auto parts suppliers have conducted in-depth research and exploration on various types of batteries, conducted a large number of targeted tests on electric vehicles and their lithium batteries, achieved a series of research results, and successfully commercialized a series of lithium battery parameter detection systems. Domestic universities such as Peking University, Tongji University, and Beijing Jiaotong University have made great progress in the research of lithium battery parameter detection systems. The lithium battery parameter detection system developed by Harbin Guantuo Co., Ltd. jointly established by Harbin Institute of Technology and Beijing Institute of Technology has been applied to some domestic electric vehicle brands [3] [4].
This subject design is mainly based on the STM32F103RBT6 chip as the core, using DS18B20 temperature sensor and INA219 sensor as parameter detection components to design a detection system that can detect the parameters of electric vehicle lithium batteries. The battery parameters detected by the system will be displayed on the display screen and the system is also equipped with an alarm circuit. If the current and temperature of the system exceed the set value, the buzzer will sound an alarm.
2. Overall Design of the Detection System of Parameter Test System
2.1. The System Structure Diagram of the Detection System
The process of design of the detection system structure diagram is based on the expected goals of the detection system. It is planned to use current detection module and voltage detection module to detect the lithium battery of electric vehicles. This subject designed and produced a lithium battery parameter detection system based on STM32F103RBT6, using STM32F103RBT6 microcontroller as the main controller, integrating various modules, realizing the functions of each module, and completing the detection of lithium battery parameters. The system architecture diagram is shown in Figure 1. As shown in Figure 1, the system consists of the temperature detection module, the OLED display module, the current detection module, the voltage detection module, the power module and the buzzer alarm module.
2.2. The Working Principle of the Detection System
For temperature detection, the temperature sensor DS18B20 developed by USA DALLAS is used to realize the detection of the temperature parameters of the lithium battery, and the detection of current and voltage is realized by using the INA219 sensor. The working principle of the detection system: turn on the power and the system initializes. The system uses DS18B20 to detect the temperature of the battery and returns the data to the single-chip microcomputer, and then uses the INA219 sensor to detect the voltage and current and transmits the detected data to the single-chip microcomputer through the ADC analog-to-digital conversion module. And finally displays the parameters through the OLED display module. These real-time parameters are compared with the current and temperature set by the system. If the upper limit is exceeded, the alarm circuit will be triggered.
3. Hardware Design of the Detection System
3.1. Hardware Circuit Schematic
The detection system microcontroller I/O port and resource allocation table is shown in Table 1.
![]()
Table 1. The detection system microcontroller I/O port.
3.2. Selection and Demonstration of the Main Control Chip
The highest operating frequency of the STM32F103 chip is 72 MHz, with single-cycle hardware multiplication and division performance, the program storage area FLASH ranges from 32 K to 512 K bytes [5], and it can support up to 64 KB of SRAM running memory. And the controller has excellent power consumption control and can achieve low power consumption; and it does not require an expensive emulator during development, and the code can be programmed through J-Link simulation or serial port. Combined with the actual research in this article, the ARM microcontroller STM32F103RBT6 was finally selected, which is suitable for the main control chip of the low-cost battery detection system.
3.3. Selection and Justification of Temperature Sensor
Figure 2 shows the temperature sensor of DS18B20. The DS18B20 sensor is currently mainly used to measure the temperature. Compared with the traditional thermal resistance sensor, it can read the temperature [6]. Detailed description: SPI can directly realize the digital reading method of nine-digit and twelve-digit numbers, which can complete 93.7 ms and 750 ms read and write respectively. Data from DS18B20 or to DS18B20 must only be read, and written from the data bus to the interface temperature switch power supply.
Therefore, DS18B20 will make the circuit board streamlined and stable. Compared with DS1820, it has improved accuracy for measuring temperature, transmission time, distance and resolution, and has a good application. Bring more accurate and convenient results to users.
3.4. Selection and Justification of Voltage and Current Detection Module
Figure 3 is the voltage and current detection module. INA219 provides two levels: A-level and B-level. Class B models have higher accuracy and stricter precision specifications [7]. INA219 can sense the partial voltage in the bus in the range of 0 V to 26 V. The device is powered by a single power supply from 3 V to 5.5 V, and the maximum current consumption of the power supply is 1 mA. The operating temperature range of INA219 is −40˚C to 125˚C.
3.5. Selection and Justification of OLED Display Module
The display module uses a 0.96 inch OLED IIC interface screen. The display area
![]()
Figure 3. Voltage and current detection module.
is a 128 × 64 dot matrix. Each dot can emit light, so it has no backlight. It can display Chinese characters, ASCII, patterns, etc., and the contrast is very high. Without backlight, the display unit can self-illuminate with a high resolution of 128 × 64, a large angle of 160˚, and support many control chips, which are fully compatible with STM32, ARDUINO, 51 series, MSP430 [8] [9].
4. Software Design of the Detection System
After turning on the power switch, the lithium battery parameter detection system first initializes the system clock, system delay function, serial port, DS18B20 sensor function, INA219 sensor function, buzzer function and OLED function (Figure 4). The lithium battery parameter detection system obtains parameters such as current, voltage, and temperature by calling the corresponding sensor function, and then displays the data on the display module, and compares the data to determine whether a fault has occurred. The main program is shown in Figure 5.
5. Product Commissioning
5.1. Commissioning of Temperature Detection Circuit
Figure 6 is the Temperature detection chart. Connect the connected temperature detection circuit to the PA0 pin of the single-chip microcomputer, connect the 3.3 V voltage, connect the single-chip microcomputer to the computer through the serial port, open the hyper terminal, and verify whether the temperature detection circuit works normally. As shown in Figure 6, the data measured by the temperature detection circuit is basically normal.
5.2. Commissioning of Current and Voltage Detection Circuit
Figure 7 is the Temperature detection chart. Connect the INA219 sensor to the
MCU SDL to PA5, SDA to PA6, VIN+ to the positive electrode of the battery, VIN− to the negative electrode of the battery through the load, connect the 3.3V voltage, connect the MCU to the computer through the serial port, open the super terminal, and verify Whether the current and voltage detection circuit works normally, the current and the data measured by the voltage detection circuit are basically normal, which are shown in Figure 7.
5.3. Commissioning of the Detection System
Connect the debugged modules to the corresponding MCU pins according to the circuit diagram, and then connect to the power supply to see the battery temperature, voltage, current and other parameters on the display. At this time, the measured temperature value is 33 degrees, the voltage value is 2.267 V, and the current value is 62 mA. The system is also equipped with an alarm circuit. When the current and temperature exceed the set upper limit, the buzzer will sound an alarm and display the warning character “!”, the temperature setting value is 32˚C, the current setting value is 1 A, and if the detection parameter exceeds the set value, it will alarm. The hardware debugging is shown in Figure 8. As shown in Figure 8, the alarm module is activated and the red light is on. At this time, the temperature value exceeds the set value, and an alarm occurs, and the current and voltage data are displayed normally. It shows that although the system is in an alarm condition, the current and voltage measurement modules can still work normally, and it appears that the entire system has strong anti-interference ability.
![]()
Figure 7. Current and voltage detection chart.
6. Conclusions
Take the OLED display module as the parameter display, take the buzzer as the alarm circuit of the system, take the STM32 single-chip microcomputer as the core component, and then carry out software programming, and finally realize it with C language. Then make the actual product and start the function debugging. During this process, some details of the design plan have been improved to better complete the design of the lithium battery parameter detection system. Finally, experimental studies have been conducted to verify the expected functions.
This article also designs the hardware circuit of the lithium battery parameter detection system. The system is a lithium battery parameter detection system with STM32F103RBT6 as the core chip combined with temperature detection circuit, INA219 sensor circuit and display circuit. The measurement of the basic parameters of the battery is the prerequisite for the estimation of the state of charge. This article introduces the relevant theoretical knowledge of the detection module in detail, designs the current and voltage detection circuit based on INA219, and uses the temperature measurement circuit based on the DS18B20 temperature sensor.
In summary, the electric vehicle lithium battery detection system based on STM32 single-chip microcomputer designed in this subject can measure parameters such as battery current, battery voltage, temperature, etc. The interface is intuitive and clear, but there is still much room for improvement as a whole.
Acknowledgements
This research was supported by the Doctoral Research Initiation Fund of Guilin University of Technology (GUTQDJJ2018068) and 2020 Guangxi University Middle-aged and Young Teachers' Basic Research Ability Improvement Project (2020KY06024).