The solution introduced in this article combines the advantages of GPRS (General Packet Radio Service) technology, such as always online, fast speed, wide access range, small size, and low power consumption, and adopts RS485 industrial bus to design and implement a home intelligent controller based on embedded system. Users can realize remote wireless monitoring through SMS and the Internet, which provides users with a simpler and more convenient choice in today's popular mobile phones and the Internet. At the same time, due to the special design of the RS485 interface of the controller, the external nodes can be expanded from the original 32 to 64, solving the wiring networking and control problems of home appliances.
1 System Design
From the structural point of view, it is mainly divided into three parts: user, controller, and home appliance control of RS485 bus. The user sends commands to the GPRS module of the controller through mobile phone text messages or the Internet, and the controller also feeds back information or sends alarm notifications to the user through the GPRS module. Thus, the user and the controller are wirelessly connected and remote control is realized.
2 Hardware Design
The block diagram of the hardware part is shown in Figure 1. The controller is the core of the whole system. It is connected to the GPRS module through serial port expansion. It provides RS485 bus interface to connect to home appliances through level conversion chip. It also provides interactive interfaces such as LCD and keyboard. The main control chip of the controller adopts Samsung S3C44B0, uses ARM7TDMI core, and operates at 66MHz[1]. The processor is connected to 4MFlash (used to store the startup code and system code of the controller and the text log of the day's events) allocated to the memory Bank0 space and 4M×16 SDRAM allocated to the memory Bank6 space.
GPRS module peripheral circuit: The GPRS module adopts Siemens MC35 module, which supports multiple communication methods such as data, voice, short message and fax, and can be controlled by AT commands. The serial line can be directly connected to the RS232 serial port after level conversion by MAX3238. Serial port expansion: 44B0 provides a complete 9-wire serial port for GPRS modem dial-up Internet access through an external dual-channel universal asynchronous receiver and transmitter ST16C2550. Its main features are that the receiving and sending have 16 bytes of FIFO (first in first out) buffers, and the independent baud rate generator can provide 50bps to 4Mbps transmit and receive clocks. Users can easily locate errors and judge the operating status through the chip's status register. The chip memory space uses the reserved storage space bank4. It adopts bus control. RS485 interface design: Using TI's RS485 interface chip 75L BC184, it can realize the conversion between the TTL level of the 44B0 serial port and the RS485 level. The input impedance of the chip is twice the standard input impedance of RS485 (≥24KΩ), so 64 nodes can be connected on the bus (equivalent to twice the original). And it has a unique design. When the input end is open, its output is high level, which can ensure that when there is an open circuit fault in the cable at the receiver input end, it will not affect the normal operation of the system.
3 RS485 bus protocol design
The transmission protocol of the RS-485 bus needs to be specified for system communication. The most important thing is the design of the frame structure. The structure of the data frame of this system includes seven parts: start, address, type, data length, data, checksum and end frame. Except for the data frame which is N bytes (depending on the data transmitted by the slave), the rest occupy 1 byte. The definition of type word is shown in Table 1. The "SEN DDATA" frame in the type frame is a data frame, which is used to store the status information of the slave device. The other 4 types are command frames, which are used to store the command words sent by the host to the slave.
The host sends a query request. The host sends a read request. The slave is ready to receive. The slave is busy. The master/slave sends data
This system uses the LRC frame check method. The LRC value is calculated by the transmission device and placed in the message frame. The receiving device calculates the LRC during the message reception process and compares it with the value in the LRC field in the received message. If the two values are not equal, it means that there is a transmission error. In addition to the definition of the frame structure, the communication of the entire system also needs to comply with the following rules: (a) Host query method: The host polls each slave and requires the slave to submit status information. The slave cannot actively send a request. (b) When the host sends an "ASK" command, if the slave feeds back a "BUSY" frame, the host starts timing and counting. If the timeout is 3 times, the task execution fails. (c) After the host receives the "READY" signal sent back by the slave, it sends the "GETDATA" command to the slave, enters the receiving state, and turns on the timeout control. If the data sent back by the slave is not received within the specified time, the counter is incremented by 1 and the "GETDATA" signal continues to be sent. If the timeout is 3 times, the query is canceled. (d) The slave waits for the host to send instructions and performs corresponding operations according to the specific instructions. If the received command frame is wrong, the frame will be discarded directly.
4 Software Design
The design of the software part is mainly based on ARM-Linux, because the operating system has a complete TCP/IP protocol and also supports many other network protocols, which can provide complete protocol support for GPRS modem to connect to the Internet, and the operating system has good stability and real-time performance to meet the requirements of home intelligent controllers for system reliability. In addition, Linux source code is open and highly portable, providing good technical support for problems in system development. The software design of this system mainly consists of two parts of the application: GPRS wireless data transmission; RS485 bus control.
4.1 RS485 bus control
Based on the RS485 bus protocol in the previous section, the master-slave control is mainly divided into three parts: polling, query, and control. (1) Polling: The host periodically queries each slave. If an alarm message is found, it is saved and triggered in time and fed back to the user. If a timeout or frame error occurs, the host abandons the query and stores the event in the host. (2) Query: The query workflow is roughly the same as polling, but only the specified slave and specified status are queried. (3) Control: Send the control command to the specified slave and require the slave to feedback the execution result.
4.2 GPRS wireless data transmission
4.2.1 Receiving and sending SMS messages
(1) Encoding conversion: To send Chinese text messages, you need to use the 16-bit encoding of the PDU mode. In the Linux system, GB2312 is used by default to save Chinese characters. Before sending a text message, you must first perform encoding conversion, convert GB2312 to Unicode encoding, and then convert Unicode encoding to PDU 16-bit encoding. Here we use the iconv () function in Linux, which can implement the conversion between any two encodings supported by Linux. Implementation method: First, use iconv_open() to open a conversion handle, specify the two encodings before and after conversion. Then use icnov() to convert. Finally, use iconv_close() to close the handle and release resources. After the conversion is completed, it can be sent correctly. (2) Sending: Send an AT command to the MC35 module. If an OK response is received, it means that the controller and the GPRS module are communicating normally. Set the SMS center number and SMS format (PDU) through the "AT+CSCA="***" and AT+CSCA=0 commands. Then send AT+CMGS = "phone number" and get the prompt symbol ">". At this time, you can send the edited PDU code to the MC35 module and end it with "CTRL+Z". If an OK response is received, the sending is successful; if an ERROR is received, it means that the sending failed. Reinitialize the MC35 module and send the message [4]. (3) Receiving: When receiving a text message, send "AT+CMGR=X" to read the short message from the SIM card and call the SMS processing program for corresponding conversion.
4.2.2 Implementation of GPRS networking under Linux
GPRS networking is implemented by Linux's PPP protocol. Therefore, when compiling the kernel, you need to add PPP support to the Linux kernel [5]. Then, according to the configuration information provided in the program, including the mobile APN*/ as "CMNET", the communication protocol IP, the dial-up number "*99***1#", the serial port device number /dev/ttyS2, the baud rate 9600, the user name, the password and other information, configure the five scripts and configuration files required by the PPP protocol: ppp-on, ppp-off, options.gprs, dialer.gprs, pap-secrets. After completing the settings, run ppp-on to perform GPRS dialing; run ppp-off to disconnect.
GPRS networking process (controller as client): (a) When the user wants to access the GPRS module through the network, he can send a networking command to the host GPRS module via SMS, including the user's IP address and related configuration information. (b) The host obtains the configuration information of the GPRS Internet connection based on the user's SMS, and generates the corresponding dial-up script and configuration file. Call the ppp-on script for PPP dial-up. (c) Determine whether PPPD dial-up is successful, the sign is whether the ppp0 network device can be generated. (d) During the data transmission process, the watchdog is used to observe the network connection status in real time. When the network is disconnected, the host saves the current data status, restarts the GPRS module and restores the connection. (e) When completing this task, the user sends a command online to let the controller call ppp-off to disconnect.
4.3 System Software Process
The software flow is shown in Figure 2. After the system is powered on, it first initializes the serial port, LCD, keyboard, GPRS module, and network configuration files. It also detects whether the GPRS module and the host are communicating normally. Then it starts polling the slaves. When an alarm is found, it reads and stores the alarm information, starts the alarm, and notifies the user of the corresponding alarm information through dialing and SMS. When receiving a user command, it first determines the user's control method and then responds.
5. Summary and Outlook
The whole scheme proposes detailed solutions to the main problems in the implementation of the home intelligent controller system, and its feasibility has been proved in practice. In addition, since the controller has the basic functions of the GPRS controller, it can be used as other wireless remote control devices by simply making corresponding modifications in the application program, which is universal and extensible.
Previous article:Design of a method to shorten the shutdown time of μC/OS-II real-time kernel interrupt
Next article:Design of computer mouse control system based on STM32F
- Popular Resources
- Popular amplifiers
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
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- 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
- Exclusive violent disassembly of active noise reduction neck-worn voice smart headphones
- How does the Keil compiler support circular linked lists?
- Introduction to TI_DSP link command file (*.cmd)
- [Operation Tutorial] ATG-2042 power signal source, one machine with two functions
- 【Iprober 520 current probe】Magnetic field mode test and test summary
- [Perf-V Evaluation] + FPGA Flowing Light
- Why signal isolation is important in 48V HEV/EV systems
- Protel99se has a DDB file that cannot be opened
- USB virtual serial port send interrupt
- 6 Elements of Brushless DC Motor Control