Introduction
When downloading programs, traditional MCU control systems usually remove the chip and burn it with a programmer, or use ISP to perform online programming. With the continuous changes in user needs and usage environment, the system program will be required to be upgraded, and the two methods mentioned above must be operated on-site by developers. This upgrade method undoubtedly greatly increases the development cost for terminal-distributed control systems and delays the update time of the program. Therefore, this article combines the wireless base station dynamic environment monitoring system and gives a specific implementation method based on the mPSD32xx series of MCU wireless remote IAP (in-application programming) to solve the above problems.
System Architecture:
The power supply, air conditioning, indoor environment of the wireless base station and other conditions are crucial to the normal operation of the entire system. In order to provide a stable and reliable operating environment for the wireless base station, this acquisition system is designed.
In view of the above environment, the lower computer of this acquisition system integrates the power supply, air conditioning, temperature, humidity, smoke, door control, etc. of the base station, collects various data required by the system in real time, and provides automatic alarm function; the upper computer uses C/S mode to set different levels of authority to provide to each monitoring center. The data transmission of the system uses GPRS/GSM wireless communication network to access the Internet for remote transmission: the lower computer automatically uploads the alarm information to the monitoring center or mobile phone through GPRS/GSM; at the same time, the monitoring center or mobile phone can query and configure the collector through the GPRS/GSM network to meet different actual needs. In the design process of the entire system, in order to efficiently schedule multiple tasks, the mCOSII embedded real-time operating system with open source code was selected.
Hardware Design Principles
Introduction to mPSD32xx Chip
mPSD32xx includes a standard 8032 microcontroller module and a PSD module. Using modular design technology, not only are multiple functional blocks required to form a single-chip microcomputer application system (such as 8032 core, two Flash, SRAM, I/O, PLD, USB interface, I2C interface, dual UART ports, DDC channel for LCD display, PWM controller, 4-way ADC, etc.) integrated on a single silicon chip, but it can also be programmed in the system through JTAG ISP mode, which can simplify the design of embedded application systems, shorten product development cycles, improve system reliability, reduce costs and reduce product size.
Since the mPSD32xx series products have two memories, the main Flash and the second Flash, designers can remotely update the Flash without the need for external memory and perform in-application programming on it.
Hardware Interface Design
The level conversion in the serial port uses the MAX202CPE chip of Maxim. Since the GPRS module and the door control system module are connected to the serial port 0 of the mPSD3234A at the same time, the 74LS11 AND gate chip is used in the reception of its serial port 0.
Hardware Configuration
The main Flash memory consists of 8 sectors, and the second Flash memory consists of 4 sectors. The configuration of Flash can be realized by software PSD EXPRESS, and the configuration results are as follows:
The first Flash is only used as data space: FS0: 0~0x1FFF & 0x8000~0xFFFF (page number is 0)
FS1~FS7: 0x8000~0xFFFF (page number is 1-7)
The second Flash is only used as program space: CSBOOT0: 0~0x1FFF & 0x8000~0x9FF
CSBOOT1: 0xA000~0xBFFF
CSBOOT2: 0xC000~0xDFFF
CSBOOT3: 0xE000~0xFFFF
RS0: 0x2000~0x3FFF
CSIOP: 0x200~0x2FF
When downloading the program, download the startup program to FS0, 0~0x1FFF and CSBOOT0, 0~0x1FFF. User programs are downloaded to FS0~FS7, 0x8000~0xFFFF.
Software Design and Implementation
GPRS and Modules
The GPRS module selected for this design is Q2406B from WAVECOM, which is a dual-band GPRS/GSM module (EGSM900/1800MHz or EGSM900/1900 MHz) with a complete built-in TCP/IP protocol stack. It can access the Internet directly through AT commands, and its design and development complies with the ETSI GSM Phase 2 standard. The microcontroller communicates with this module through the serial port using a baud rate of 9.6 kbps in full accordance with standard AT commands.
The module initialization procedure is as follows:
void GPRS_init()
{
mPSD_UART_Putchar ("AT+CMGD=1,4",0);?? //Delete all text
messagesmPSD_UART_Putchar ("AT+CRES",0);?????? //Release GPRS module
memorymPSD_UART_Putchar ("AT+CSCA?",0);????? //Query the short message center numbermPSD_UART_Putchar
("AT+CMGF=0",0);???? //0: PDU mode, 1: text
modemPSD_UART_Putchar ("AT+CMEE=1",0);?????? //Open the error code prompt informationmPSD_UART_Putchar
("AT+CNMI=0,1",0);???? //Open the short message prompt informationmPSD_UART_Putchar
("ATE0",0);??????????? //Close
the echomPSD_UART_Putchar ("AT&W",0);
?}
Among them, the mPSD_UART_Putchar ("ABCD",0) function is: mPSD3234A sends the string "ABCD" to the GPRS module through serial port 0.
Introduction to IAP
IAP is a programming mode applied to the Flash program memory. Under the control of the application program, the program storage space can be read, erased, and written. It is very similar to the ISP operation. There is no need to remove the chip from the circuit board and burn it with a programmer. Both have online programming functions. The difference between the two is that ISP usually erases and programs the entire chip, and downloads the program to the Flash through the PC serial port under manual operation, while IAP reads and writes another program Flash under the control of a certain program. [page]
Implementation of IAP
IAP is to start the program to program the new user program into the specified Flash. The read/write operation of the Flash program memory is the key to the implementation of IAP, which is described in detail below. The
MCU can read the Flash memory like a ROM device, but can only use special erase and program instructions to program the Flash memory.
The Flash memory must be erased before it can be programmed. A byte of the Flash memory is erased to all 1 (FF h), and is programmed by setting the select bit to 0. The MCU can erase all Flash memories or a sector at once, but cannot erase by byte, while the MCU can program by byte. Once the MCU issues a Flash memory programming/erase instruction, there are several ways to determine whether the programming/erasing is completed. The following two judgment methods are used in the program to program the Flash.
Data polling method
The programming of the data polling method is completed by the function unsigned char? flash_boot_write_ with_poll(volatile uchar xdata* addr, uchar dat). When the command received from the monitoring center is to update the old user program using the data polling method, this function will be called in the main program, the MCU will issue a programming instruction, and the built-in algorithm will start running. The error flag (DQ5) bit is 1 to indicate that the programming cycle has timed out, and 0 to indicate that there is no error. The MCU can read the data polling (DQ7) bit and the error flag bit at any position of the programmed sector.
Data jump method
The programming of the data jump method is completed by the function unsigned char flash_write_with_toggle (volatile uchar xdata* addr, uchar dat). The programming cycle is roughly the same as the data polling method, except that the MCU reads the data jump flag (DQ6) bit instead of DQ7. During programming, the DQ6 bit keeps jumping until the programming cycle is completed. The DQ5 bit is 1 to indicate that the programming cycle has timed out, and it is 0 to indicate that there is no error. The MCU can read the DQ6 bit and DQ5 bit at any position of the programmed sector.
In addition, this chip also has a Flash memory sector protection function: each sector of the main Flash and the second Flash memory can be individually protected to prevent programming and erasure. This function provides additional data security for all programming or erasure failures.
In this design, the CSBOOT1 sector of the second Flash stores some fixed card numbers for gating, and this sector should be protected. The remaining sectors of the second Flash are used as backup to save some power or air conditioning parameters and the gate control card number that needs to be added. These data are variable and therefore not protected. The Flash storage sector can be protected or unprotected through the JTAG port or device programmer. The MCU can read the sector protection status by reading the sector protection register (in the CSIOP block), but cannot change it.
Main program design of IAP function
After the system is powered on, the program first runs in the boot sector, waiting for commands from the host computer and performing corresponding operations according to the commands (see Figure 2). It automatically switches to the user program when it times out or no command is sent. When the user program needs to be updated, switch back to the boot program.
Exception handling
There are three main situations in the system operation that will cause the program upgrade to fail: power failure, communication interruption, and bit error. The following briefly introduces some protection measures taken by this design. In
the first case, the poor power supply stability caused by the environment and the interference of high-voltage signals such as lightning and relays are taken into account. The system uses a high-isolation DC/DC power supply module to isolate the external ground from the system ground, and adds a high-speed optical coupler to the serial port part that is easily interfered with for isolation; In the second case, the system uses a complex communication network composed of serial ports, GPRS/GSM, and TCP/IP. Since any communication failure will cause the communication between the upper and lower computers to fail, in order to prevent the system from being paralyzed due to communication failure, the program uses the Eeprom_Init function to recover and repair the data in the case of communication failure or power failure; In the third case, during the communication between the upper and lower computers, although the communication is normal, there is a possibility of bit errors due to the large amount of data. Therefore, the program first checks the frame type for each frame of data received, and then performs a 4-byte checksum judgment on it. If the check is wrong, the error information type is sent back to the upper computer for retransmission until the data is completely correct, and then the frame of data is saved to the corresponding address of the Flash.
Conclusion
The wireless remote IAP introduced in this article is based on the mPSD32xx series of microcontrollers and has been used in the wireless base station dynamic environment monitoring system project, which greatly facilitates the timely update of the system program and its reliability has been verified. It can be directly applied to various power, water resources and other wireless monitoring systems.
References:
[1]. GPRS datasheet http://www.dzsc.com/datasheet/GPRS_1594650.html.
[2]. DDC datasheet http://www.dzsc.com/datasheet/DDC_1870710.html.
[3]. Maxim datasheet http://www.dzsc.com/datasheet/Maxim_1062568.html.
[4]. MAX202CPE datasheet http://www.dzsc.com/datasheet/MAX202CPE.html.
[5]. 74LS11 datasheet http://www. dzsc.com/datasheet/74LS11_1493173.html.
[6]. Q2406B datasheet http://www.dzsc.com/datasheet/Q2406B_561524.html.
[7]. ROM datasheet http://www.dzsc.com/datasheet/ ROM_1188413.html.
Previous article:Implementation of TCP/IP Protocol on VRS51 Single Chip Microcomputer
Next article:Design and Implementation of 80C196 Single Chip Microcomputer Simulation Software
Recommended ReadingLatest update time:2024-11-16 15:54
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- IMX6ULL development board [Ultimate] Development board assembly process before use
- [McQueen Trial] Python driver for HCSR04 ultrasonic sensor
- FPGA pipeline design
- 【Qinheng CH582】6 CH582 four low power mode current measurement
- Recently, there have been frequent incidents of electric vehicle explosions and fires. What do you think about this? ?
- Explanation of several clock frequencies in LPC2478
- Real-time Zooming Module of Digital X-ray Image Based on FPGA
- 【LAUNCHXL-CC1350-4】- 5: A method to install XDCTools on Windows 10 has also been found. . .
- There are several packaging issues in PCB components
- Read the good book "Operational Amplifier Parameter Analysis and LTspice Application Simulation" + First Reading Experience