Currently, many application fields use wireless methods for data transmission. Wireless RF data transmission modules are widely used in wireless meter reading, industrial data acquisition, antenna remote control, computer telemetry and remote control, medical and health automation, home automation, security, and automobile instrument data reading. 1 Construction of RF Data Transmission Module Development Platform Establishing a software and hardware development platform is the primary task of module development. After comparing several RF data transmission module solutions, we finally decided to adopt a development solution with LPC900 series FLASH microcontroller and CC1000 RF transmission chip as the main chip. 1.1 Introduction to the main chip LPC2900 FLASH microcontroller is a 51 core microcontroller launched by Philips with high performance, micro power consumption (power consumption in full power-down mode is less than 1μA), high speed (6 times that of ordinary 51 microcontrollers), and small package. It mainly integrates a series of distinctive functional components such as byte-mode I2C bus, SPI bus, enhanced UART interface, comparator, real-time clock, E2PROM, AD/DA converter, ISP/IAP online programming and in-application programming, which can meet various applications that have restrictions on cost and circuit board space but require high performance and high reliability. Based on various factors such as performance and cost, we chose the LPC922 of this series. CC1000 is a programmable, half-duplex UHF monolithic transceiver chip based on Chipcon's Smart RF technology. The circuit operates in the ISM band (300-1 000 MHz). Through serial interface programming, its main operating parameters can be flexibly and conveniently set according to the needs of different applications. At the same time, its sensitivity can reach -109 dBm, programmable output power -20-10 dBm, FSK modulation data rate can reach up to 76.8 kBaud, and can operate at a low power supply of 2.7-3.3 V. It is very suitable for applications in ISM (industrial, scientific and medical) and SRD (short distance communication). 1.2 Development platform construction The LPC900 series MCU provides relatively complete software and hardware development tools. In system development, the TKS932 simulator is used for system simulation and debugging. The simulator supports the currently popular μVisionⅡ integrated development environment of KEILC. The block diagram of the RF data transmission module development platform is shown in Figure 1, which is constructed by using a self-designed RF module development board and adding some auxiliary circuits, in conjunction with the TKS932 simulator and the software development tool μVisionⅡ.
The COM1 port of the PC communicates with the TKS932 emulator to perform software and hardware simulation on the module software. The COM2 port communicates with the LPC922, which can reflect the software debugging information more intuitively and assist in software debugging; on the other hand, it can receive or send data to the RF module through the serial port. 2 Software Development and Debugging 2.1 Basic structure description of data transmission module software The RF transmission chip CCl000 has three states: IDEL (idle), RX (receive data), and TX (send data). Overall, this is a state machine model with three states. The mutual conversion between states is shown in Figure 2. In addition to completing the basic chip initialization work, the main program of the module mainly runs according to the interrupt generated by the DCLK pin of CC1000. The interrupt management program performs state detection and switching, and executes corresponding interrupt operations.
2.2 Analysis of Problems Encountered in Software Debugging and Development The software development environment used in this development platform is μVisionⅡ. This environment is embedded with a variety of development tools that meet current industrial standards, and can complete the complete development process from project establishment and management, compilation, connection, target code generation, software simulation, hardware simulation, etc. In particular, the C compiler tool has achieved a high level of accuracy and efficiency in generating code, and can add flexible control options, which is ideal for developing large projects. Even if you do not use C language but only assembly language programming, its convenient integrated environment and powerful software simulation debugging tools will greatly speed up the development progress. However, its development environment has its own characteristics, and some special issues need to be considered. The following is a specific discussion and study of several typical problems encountered in software development. 2.2.1 Keywords in the program You cannot use C51 compiler keywords to define variable names or function names when programming. C51 distinguishes between uppercase and lowercase letters, and keywords are all lowercase. For example: void writeToCC1000Register(char addr, char data). There is no problem with the function definition literally, but an error is indicated during compilation. After checking the C51 keyword directory, it is found that the reason is that the variable parameter data is its keyword, which causes an error during compilation. The following are some commonly used keywords that should be avoided when defining variables or function names during program design: _at_, alien, bdata, bit, code, data, idata, large, pdata, sbit, sfr, sfrl6, smal, task, using, xdata, priority. 2.2.2 The difference between BIT and SBIT and the use of global variables and local variables When operating on bits in a program, two data types must be involved: bit and sbit. The difference between these two data types should be noted. Bit is mainly used for bit variable operation. Although sbit is also used for bit variable operation, its application range is wider than bit. Sbit can not only be used to define the bits of bit-addressable registers, so that we can perform bit operations on registers, but another important function of sbit is to construct a data type similar to a union. This data type plays an important role in the serial/parallel data conversion between LPC922 and CC1000. For example: unsigned char bdata myDatas2; //define a bit-addressable global variable //define each bit of the variable sbit cDatas0=myDatas2^O; sbit cDatas1=myDatas2^ 1 ; sbit cDatas2=myDatas2^2; sbit cDatas3=myDatas2^3; sbit eDatas4=myDatas2^4; sbit eDatas5=myDatas2^5; sbit cDatas6=myDatas2^6; sbit cDatas7=myDatas2^7;
Here myDatas2 can be used as an 8-bit variable, and each bit can also be used separately, which is very useful in serial/parallel data conversion. It is particularly important to note that myDatas2, a bit-addressable variable, must be defined as a global variable. If it is defined as a local variable, the compiler will also generate an error. 2.2.3 UART communication and function call When performing hardware simulation, UART serial communication between LPC922 and PC is required, so that the relevant debugging information can be intuitively displayed on the hyperterminal. In the early stage, there was always a communication problem, so the underlying code related to serial port reading and writing was debugged and the problems that occurred were corrected. The original microcontroller and PC serial port communication program is as follows: The original UART write string function writeln is implemented by calling the putchar function, but errors always occur during hardware simulation. When this part of the program is separated for simulation, no problems occur. Later analysis and consideration led to the possible reason: Due to the limitation of internal stack space, C51 provides a compressed stack when calling a function. Each process is given a space for storing local variables. Each variable in the process is stored in a fixed position in this space. When the process is called multiple times or recursively, the variable will be overwritten and an error will occur. At this time, the function should be defined as a reentrant function, but reentrant functions generally run slower because they have to do some special processing. When writing the UART operation to call the putchar function in this program, other parts of the program are also calling the function, overwriting the parameters passed to the putchar function, causing the program to run incorrectly. So the program was modified as follows: The difference between the modified program and the original program is that the putchar function is no longer called, but the relevant operations are performed directly. After the modification, the problem was well solved by hardware simulation. Similar problems were encountered in the operation of reading and writing CC1000 registers. The problems were solved by modifying the function call. From this, we can see that due to the limited internal stack resources of the LPC900 microcontroller, when the program is found to be running abnormally during program design, special attention should be paid to the problems caused by function calls. Of course, there may be other reasons for this problem, which require further analysis and research. 2.2.4 Watchdog When performing software simulation, the program always resets and jumps. According to breakpoint tracking, it is analyzed that the problem is related to the time factor of program running. The relevant LPC900 chip data is checked, and the watchdog part is studied in particular. When the system is in some harsh environments (industrial control, bottom-level acquisition, etc.), if the system's anti-interference is not done well, it is easy to "freeze". At this time, the hardware circuit is not damaged, but the internal program runs incorrectly and must be reset to recover. At this time, the "watchdog" can be used to solve the problem. The watchdog timer subsystem can restore the system from incorrect operations by resetting. However, everything has its two sides. When the software fails to clear or reassign the timer before it overflows, the watchdog timer will cause the system to reset once, resulting in an error. The simulation development board uses LPC922, so the registers related to the watchdog during reset are analyzed in detail. Finally, it is found that the problem is caused by not reconfiguring the parameters of the watchdog in a timely manner within a certain period of time. By reasonably configuring the four registers related to the watchdog, WDCON, WDL, WFEED1, and WFEED2, the program reset problem is well solved. 2.2.5 LPC900 read operation and CC1000 register read and write LPC900 series microcontrollers usually have some characteristics of 51 microcontrollers, and you should pay attention to them when using them. When its I/O port is used as an input port, there are two working modes, namely, reading the port and reading the pin. Reading the port does not actually read data from the outside, but only reads the contents of the port latch to the internal bus, and then writes it back to the port latch after some calculation or transformation. When reading the pin, the external data is actually read into the internal bus. At this time, you must first pass the instruction to set the port latch to 1, and then read the pin operation, otherwise it may be read incorrectly. In the process of reading and writing CC1000 registers of LPC922, it involves problems related to reading pin operations. These two working modes should be distinguished to avoid errors. 3 Conclusion On the development platform introduced in this article, the LPC900 series microcontroller is used to realize the effective parameter read and write configuration control of the CC1000 register on the RF module according to different application needs, and the design requirements are preliminarily met. After further improvement, the module can be used in many fields such as wireless data transmission. The analysis and discussion of the problems encountered in software development also has a wide range of practical significance in the application development of the LPC900 series microcontroller.
|