The interface between single chip microcomputer and MODEM and the scheme of controlling MODEM by AT commands

Publisher:精品古钱斋Latest update time:2012-07-02 Source: 21ic Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:MCU Reference address:The interface between single chip microcomputer and MODEM and the scheme of controlling MODEM by AT commands

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

51 microcontroller learning: LED dot matrix experiment (display image)
Experiment name: LED dot matrix experiment (display image) Wiring instructions: Experimental phenomenon: After downloading the program, the 8*8 LED dot matrix displays a heart shape. Note: The J24 yellow jumper cap next to the LED dot matrix is ​​shorted to the GND end *** *********************************************
[Microcontroller]
Single chip Ethernet embedded control chip--MCU-W7100A data sheet
       W7100A iMCU is a single-chip Ethernet embedded control chip. Its structure is: embedded 8051 single-chip microcomputer + TCP/IP protocol stack + 10/100 high-speed Ethernet MAC/PHY        W7100A is an upgraded version of W7100. It adds some new features, such as memory lock function (Memory Lock), sleep mode, su
[Microcontroller]
Single chip Ethernet embedded control chip--MCU-W7100A data sheet
Application of C8051F040 MCU in speech recognition system
Speech recognition is an important technical means of human-computer interaction. According to actual needs and application scenarios, speech recognition can be divided into isolated word recognition and continuous speech recognition, specific person recognition and non-specific person recognition. The main indica
[Microcontroller]
Application of C8051F040 MCU in speech recognition system
Teach you to learn 51 single chip microcomputer step by step: light up your LED
2.1 MCU Internal Resources Three major resources: Flash: program storage space RAM: Data storage space SFR: Special Function Register 2.2 MCU Minimum System Three elements: power supply, crystal oscillator, reset circuit 2.3 LED small light Current limiting: 5~20mA (calculated by the current limiting r
[Microcontroller]
Design of multi-machine parallel communication system using single chip microcomputer
1 Introduction This article introduces a single-chip multi-machine parallel communication system, using 89C51 as the host and multiple 89C2051 as slaves. (89C2051 is a 20-pin 300MIL package with 2K FLASH E2PROM. Except for the lack of two parallel ports, it has all the functions of the MCS-51 series of
[Microcontroller]
Design of multi-machine parallel communication system using single chip microcomputer
Design of intelligent charger based on UCC3895 and PIC microcontroller
0 Introduction Modern communication equipment, electronic products, electric vehicles, UPS, etc. generally use batteries as power sources. However, most charging devices have single functions, poor versatility, and low maintenance quality, which greatly reduces the efficiency of product use. This paper uses UCC3895 a
[Microcontroller]
Design of intelligent charger based on UCC3895 and PIC microcontroller
Design of intelligent lighting control system based on 51 single chip microcomputer
For some places with long lighting time and many lighting equipment (such as school classrooms, shopping malls, etc.), the phenomenon of waste in the use of lighting systems is common. Due to the lack of scientific management and the lack of responsibility of managers, sometimes the whole room is brightly lit when i
[Microcontroller]
Design of intelligent lighting control system based on 51 single chip microcomputer
51 MCU EA=1 problem
51 MCU has a pin called EA (pin 33) as the on-chip program memory selection signal. When using the MCU with program memory 8751, /EA (pin 33) must be grounded, that is, low level is effective. The CPU starts to execute the program from the on-chip program memory. When using the 8031 ​​microcontroller, which has no p
[Microcontroller]
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号