Implementation of wireless remote IAP based on mPSD32xx series MCU

Publisher:qin199099Latest update time:2013-09-11 Source: dzsc Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Reference address:Implementation of wireless remote IAP based on mPSD32xx series MCU

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

Fast algorithm for binary-decimal integer conversion in Cortex-M0 microcontroller
Introduction     In single-chip microcomputer application systems, it is generally necessary to complete the tasks required by the system efficiently and quickly, and put the system into sleep or low-power state after the tasks are completed, so as to save system power consumption to the maximum extent and enhance th
[Microcontroller]
Fast algorithm for binary-decimal integer conversion in Cortex-M0 microcontroller
STC15 Series MCU-Environmental Monitoring Equipment
main.c /**  * Product Name: Environmental Monitoring Equipment  * Product Definition:  * (1) The microcontroller collects temperature every 1 second through the DS18B20 temperature sensor.  * (2) The microcontroller collects the time from the DS1302 clock chip every 200 milliseconds.  * (3) Real-time time display th
[Microcontroller]
Analysis of the calculation method of stack in MCS51 single chip computer programming
Using C language to program MCS51 series microcontrollers is an inevitable trend in the development and application of microcontrollers. Keil's C51 compiler supports the classic 8051 and 8051 derivatives, commonly known as Cx51. It should be said that Cx51 is an extension of C language on MCS51 microcontrollers. It ha
[Microcontroller]
Analysis of the calculation method of stack in MCS51 single chip computer programming
Serial communication experimental circuit diagram of AT89 series single chip microcomputer and PC
Serial communication experimental circuit diagram of AT89 series microcontroller and PC:
[Analog Electronics]
Serial communication experimental circuit diagram of AT89 series single chip microcomputer and PC
51 single chip ultrasonic system board circuit analysis
The competition board circuit board consists of: 51 single-chip microcomputer (STC89C52 chip, collectively referred to as 51 single-chip microcomputer) circuit, DC power socket circuit, reset circuit, crystal oscillator circuit, 5V to 3V3 step-down circuit, 0.96-inch OLED screen circuit, buzzer circuit, LED circuit, a
[Microcontroller]
51 single chip ultrasonic system board circuit analysis
AVR microcontroller refined two-way ADC code + simulation diagram
The circuit diagram is as follows:    #include iom16v.h   #include macros.h #define uchar unsigned char #define uchar  unsigned int const volatile SEG_CODE = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF}; float display = {0,0,0,10,0,0,0,10}; void delay(uint mS);          void  main() {    
[Microcontroller]
AVR microcontroller refined two-way ADC code + simulation diagram
Design of intelligent target tracking system based on PIC microcontroller
Summary: By drawing on the successful experience of embedded systems in the fields of electronic technology, signal processing, and computers, and based on the analysis of target detection and tracking algorithms, the target detection and tracking algorithms are combined with embedded technology to design a target det
[Microcontroller]
Design of intelligent target tracking system based on PIC microcontroller
Research on the design of external data storage expansion based on MCS-8051 single chip microcomputer
  0 Introduction   With the continuous improvement of the computing speed and processing power of single-chip microcomputers, they are more widely used in various fields. However, with the continuous expansion of its application fields and the continuous improvement of its integration, its internal resources can no
[Microcontroller]
Research on the design of external data storage expansion based on MCS-8051 single chip microcomputer
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号