With the continuous improvement of the degree of automation, the requirements for remote collection and transmission of field data are also increasing. Today, when telephone communication networks are quite popular, the most convenient and flexible method is to use MODEM (modem) and use the existing analog public telephone exchange network for data transmission. After several years of research, the author has developed a data transmission system under the control of a single-chip microcomputer using the public telephone exchange network as a carrier. This data transmission system is not restricted by time and region, and can track changes in field data in real time at any time, thereby facilitating remote fault diagnosis and troubleshooting.
Since there is little information about the interface between microcontrollers and MODEMs in China, this article mainly introduces the interface between microcontrollers and MODEMs and how to use AT commands to control MODEMs.
1 System composition
Figure 1 shows the system composition diagram of the remote data acquisition system. The entire system is mainly composed of two parts: the field data collector and the monitoring center. The field data collector is responsible for pre-processing the collected data and packaging it, and sending the data to the monitoring center through the field modem MODEM, the public telephone network and the monitoring center's MODEM. The monitoring center then processes, displays, stores and analyzes the received data, and sends control instructions to the site as needed. Since the monitoring center uses a direct connection between the computer and the MODEM, the hardware interface is relatively simple, and the software writing is not the focus of this article, so it will not be discussed in detail. The system has two working modes: the monitoring center calls the site to request to send data and the site calls the monitoring center to actively send data.
Figure 1 System composition diagram
2 MODEM Commands
Since MODEM is a bridge for sending and transmitting data remotely through the public telephone network, here we will first introduce the function and usage of MODEM. "MODEM is the abbreviation of "modem". The so-called modulation is to convert the digital signals of "0" and "1" into different frequency signals, modulate them to the carrier frequency, and use the telephone line to transmit the analog signal. Demodulation is the reverse process of modulation, that is, demodulating the frequency signal on the carrier frequency into the corresponding digital signal and transmitting it to the terminal controller.
At present, the MODEMs we see on the market all use Hayes-compatible command sets to manage and set the various operations and communication functions of the MODEM, and generally these commands are prefixed with AT, so these commands are called "AT commands". The following introduces several common MODEM commands, which all end with a carriage return (RETURN).
ATA: Manual answer command, forcing the MODEM to go off-hook and detect the carrier;
ATE0: No response to commands, that is, the commands sent to the MODEM are not echoed in the terminal;
ATV0: MODEM responds to information in digital form, that is, after receiving the command, MODEM returns the result code in digital form;
AT&F: Parameters are restored to factory values;
AT&D0: ignore DTR signal;
AT&S0: Set the DSR signal to ON;
ATD: issue dialing instructions;
AT&W0: Store the current parameter status of the MODEM in parameter table 0;
AT&Y0: When the MODEM is initially powered on, the stored parameter table 0 is called;
ATZ0: Reset MODEM and enable the stored parameter table of group 0;
AT&Z=X: Store phone number X in the internal memory of the MODEM;
ATDS: Dial the telephone number pre-stored in the MODEM.
So, how does the microcontroller use these instructions to operate the MODEM? The following is an example of sending the ATA command. The program is written in C51 and only the relevant part is given.
#include < P >
#include < P >
#define U8251_C XBYTE[0xfd00]
/* Define 8251 control/status word address*/
#define U8251_D XBYTE[0xfc00]
/*Define 8251 data buffer address*/
unsigned char code ATA[4]={'A', 'T', 'A', 0x0d};
/*0x0d is the return control character*/
void send-code (unsigned char code *send_addr,
unsigned char send_sum);
/*Send function declaration, the formal parameter is send
First address and number of characters sent*/[page]
void main()
{
…
send_code(ATA,4); /*Send ATA response command*/
…
}
void send_code(unsigned char code *send_addr,
unsigned char send_sum)
{
do{
while((U8251_c&0x05)!=0x05);
U8251_D=*send_addr;
send_addr++;
}while(--send_sum);
}
In order to control and operate the MODEM by the single chip microcomputer, the MODEM in this system design is initialized as follows:
AT&FE0V0&D0&S0&Y0&W0
3 Interface Circuit
Figure 2 is the interface circuit diagram of the single-chip microcomputer and MODEM in the field data acquisition system. The single-chip microcomputer uses the high-performance and low-power single-chip microcomputer W78E52B produced by Winbord (Huabang). It uses the 80C31 core and is fully compatible with MCS-51 in terms of instructions. It contains 8k electrically erasable MTP ROM (Multiple-Time Programmable ROM). Its internal serial port can perform data acquisition with other communication devices with serial ports (this part is not drawn in Figure 2);
Figure 2 Interface circuit between MCU and MODEM
Considering that the collected data is large, an 8155 is expanded as an external data storage device and also serves as a parallel data acquisition interface. Its internal 14-bit timer is used as a divider. Another 8251 is expanded to interface with the MODEM. The internal working timing of the 8251, the transmitter clock and the receiver clock require external input. In the design, the ALE signal provided by the microcontroller is used as its external input, so there is no need to design a separate divider. Since ALE will lose a cycle when the microcontroller accesses the external storage, the method shown in Figure 2 is used to make full use of system resources. According to the difference between the receiving clock input RXCLK and the transmitting clock input TXCLK, the transmitting baud rate and the receiving baud rate of the 8251 can be different. In this system, the transmitting baud rate and the receiving baud rate are the same, and are both supplied by the 8155 timer divided output TMROUT. The sending of data can be completed in the main program according to the system requirements. The receiving data buffer request output RXRDY is reversed by 74LS02 and then connected to the interrupt input INT0 of 78E52B. The receiving data is controlled by interrupt mode. The DSR signal is ignored during system design, so it is directly grounded in Figure 2.
The RS232 interface level conversion circuit uses a MSX238 with five pairs of inputs and outputs. It has its own charge pump and uses a single 5V power supply. Only one chip can provide all RS232 level drive and conversion for this system.
[page]
4 Function and principle of field data collector
The field data collector has two working modes, namely the calling mode and the called answering mode. The calling mode is that the field data collector actively calls the monitoring center; the called answering mode is that the field data collector responds to the answering instruction after receiving the call ringing from the monitoring center. In addition, the field data collector has the function of remotely setting the calling number, and its software compilation flow chart is shown in Figure 3.
Figure 3 Program flow chart of field data collector
4.1 Communication baud rate
The communication baud rate of 8251 depends on the clock input of RXCLK and TXCLK. In asynchronous mode, RXCLK and TXCLK can be the baud rate, or 16 or 64 times the baud rate. This is determined by the baud rate factor in the 8251 control word. In this system design, the baud rate factor is set to asynchronous X16, that is, RXCLK and TXCLK are 16 times the transmission baud rate. As can be seen from Figure 2, RXCLK and TXCLK are given by TMROUT of 8155, and TMRIN of 8155 is 1/6 of the system clock fosc. Therefore, the key to selecting the baud rate is to determine the time constant of the 8155 timer. If the timer of 8155 is set to continuous square wave output, the relationship between the time constant N of the 8155 timer and the timer input frequency fTMRIN and the output frequency fTMROUT is: fTMROUT=fTMRIN/N. If the frequency division coefficient of 8251 is 16, the transmission baud rate can be calculated as follows:
Baud rate = fTMROUT/16 = fTMRIN/16N = fosc/(6X16N)
This system uses a crystal oscillator with a frequency of 11.0592MHz, and fosc is 1.0592MHz. If 8251 uses a baud rate of 2400Hz to transmit data, the timer constant N of 8155 is:
N=11.0592X106/(2400X16X6)=48=30H
According to the above analysis, the initialization programming of 8155 and 8251 is as follows:
void initialize rs(void)
{
U8155_IO=0xc0; /*8155 command word initialization*/
U8155_TO=0x30;/*Send 8155 timer constant low byte*/
U8155_TH=0x40; /*Send 8155 timer constant high byte*/
U8251_C=0x4e; /* Mode control word initialization*/
U8251_C=0x37;
}
4.2 Remotely set the calling number
In this system, when the key data changes beyond the limit, the field data collector can automatically call the monitoring center, but the called phone number cannot be stored in the program's ROM. There are two reasons: First, the monitoring center's phone number may change; Second, different users are called by different phone numbers; and designing an EEPROM on the field data collector is not the best solution; the best way to solve this problem is to store this phone number in the MODEM, so how to achieve it? The AT&Z=X (X is the phone number) command mentioned above can be used for remote setting. When the monitoring center needs to modify this phone number, it calls the field data collector and transmits this phone number to the data collector, and then the data collector automatically uses the AT&Z=X (X is the phone number) command to store this number in the MODEM. [page]
4.3 Calling method
When the key data collected by the field data collector exceeds the limit, the field data collector will use the AT command ATDS to actively call the phone number stored in the MODEM to call the monitoring center, and package the key data to transmit to the monitoring center. After the monitoring center receives the information package, the system can store and analyze it for the duty personnel to judge and take action.
4.4 Calling method
When the monitoring center needs to obtain field data, it can actively dial the field data collector. In Figure 2, P1.1 of W78E52 sends a MODEM response command ATA when it detects a predetermined number of ringing signals, and after a delay waiting for the MODEM to be connected and the handshake between the two parties is successful, the monitoring center sends a request to send data command to the field data collector. After receiving the command, the field data collector transmits the real-time dynamic data to the monitoring center, so that the monitoring center can interrupt the data reception at any time, and sends a hang-up command to the field data collector. After receiving the hang-up command, the field data collector stops sending data and hangs up.
4.5 Problems and Solutions
When this system was first designed, the reset input of 8251 and the reset input of CPU were connected together. This design caused the problem that 8251 could not be reset reliably. Later, it was changed to rely on P1.0 of W78E52 to send reset pulse to 8251, as shown in Figure 2. In this way, 8251 can be reset at any time according to the need of software anti-interference. The reset program written in C51 is as follows:
void reset_8251(void)
{
P1^0=1;
ACC=0;
while(--ACC);
P1^0=0;
}
5 Conclusion
Practice has proved that this system and MODEM interface have the characteristics of simple circuit, low cost and high reliability. Good results have been achieved in practical application.
Previous article:The external interrupt analysis scheme of multiple interrupt sources in MCS-51 single chip microcomputer
Next article:Based on the C8051F330 MCU related knowledge analysis solution
Recommended ReadingLatest update time:2024-11-16 17:52
- 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
- MC33063A boost circuit, burning IC and electrolytic capacitor? With pictures, help!
- Could anyone help me see what is wrong with my amplifier circuit?
- MicroPython Hands-on (24) - Expanding the Control Panel with the Control Panel
- [Flower carving hands-on] Interesting and fun music visualization series of small projects (14) --- water cup and bottle lamp
- Does TMS320C6748 support TFTP instance in stareware?
- Asynchronous Serial Transceiver Design Report.docx
- Design of robotic arm gesture tracking and voice control system
- A new trend in home appliances, PI opens up your new life in home appliances! Download product information and answer questions to win prizes!
- Voltage acquisition circuit
- Problems with IO pin configuration when STM32 is low power