Rumah> Blog> How does the gsm module communicate with the microcontroller?

How does the gsm module communicate with the microcontroller?

March 22, 2023
51 MCU and GSM module to achieve communication

1, check the quality of the serial line

1) Plug the serial cable into the computer and short the 2 and 3 pins of the serial port with a short circuit.

2) Open the serial port debugging assistant

3) Click Auto Send, send a random data in the window of automatic sending to see if you can receive the data sent by yourself if the serial port is normal, otherwise it is bad.

2, after the completion of the microcontroller program, see if the serial port has data detection

3, the meaning of the four lights on the microcontroller communication with the module

1) DO light

Flashing all the time, the serial port communication between the serial port and the GSM module is not normal, otherwise the serial communication is normal.

2) D1 lamp

When the light is on, the module is registered on the network, otherwise the network is not registered.

3) D2 lamp

Lights up to start texting

4) D3 lamp

Lights up to indicate the end of texting

4, the connection between the MCU board and the GSM module

MCU---------GSM module

VCC--------vcc (the third leg of P5)

GND--------GND (pin 4 of P5)

RX_232 (indicating the transmission of the microcontroller) ----------- RXDPC_232 (receive of the module (P5 5th foot))

TX_232 (indicating the receipt of the microcontroller) -----------TXD_PC232 (module's hair (P6's 6th foot))

How does the gsm module communicate with the microcontroller?

Gsm module and microcontroller connection

When the MCU is connected to the GSM module, the TX and RX of the asynchronous serial communication port can be connected directly. Don't forget the ground wire.

Precautions:

1. Different single-chip microcomputers have different voltages. The input and output level of the general GSM module is 2.85V, and the level of the 51 series is 5V. Generally, the 2K resistor is connected in series on the TX output line of 51, which can basically be used. If it is a 3.3V microcontroller, this resistor can be small, a few hundred ohms.

2, GSM module itself power supply and SIM card circuit is very troublesome, first of all, most GSM modules are using FPC40 interface, the spacing of the cable is only 0.5 mm, and it is a plastic case, not good soldering. If the welding is not good, the work is unstable. Secondly, the power supply part is more troublesome. The GSM module has a large emission current and the maximum instantaneous current is 2A! Therefore, the power supply part generally uses the LM2576 high-current DC-DC converter to provide 4V voltage. The DCDC circuit design itself is not easy. Personal application is difficult and requires a circuit board. The connection is unstable. There is also a SIM card part. The communication between the SIM card and the GSM module is a complicated high-frequency process. The circuit has strong anti-interference ability. I have tried to connect them with wires. If it is not ten minutes, it will be dropped. So the SIM card part also needs to be carefully designed. Don't look at only five data lines.

Method for controlling TC35GSM module by single chip microcomputer 1. Hardware connection

The circuit shown below only needs to design a TTL to RS232 level circuit, connected to the UART port of the MCU, and the other end is directly connected to the TC35.

How does the gsm module communicate with the microcontroller?

2, the method of instruction output

The serial port of the MCU is set to mode 1 (9600, N, 8, 1), and AT+xxx is output to the UART port in ASCII code format; the data of the receiving TC35 is interrupted. A detailed list of programs (Keil C51) is given here, and the programming method is not introduced. The procedure is as follows:

//The definition of the AT command

Char code AT_Tc35[]=“AT+”; //Connected

Char code Bps_Tc35[]=“IPR=38400”; //baud rate

Char code Text_Tc35[]=“CMGF=1”; //text mode

Char code Read_Tc35[]=“CMGR=”; //Read information

Char code Erase_Tc35[]=“CMGD=”; //delete information

Char code Send_Tc35[]=“CMGS=”; //Send information

Char code Creg_Tc35[]=“CREG?”; //Register

/ / mode settings

Void UART_Init(void)

{

SCON=0x50; //01010000b="1 mode scon, #11011000b;

ES=l;

}

//send - ASCII

Void SendASC(unsigned char ASC)

{

Bit es;

Es=ES;

ES=0; / / close interrupt

TI=0;

SBUF=ASC;

While(!TI);

TI=0;

ES=es;

)

/ / Send commands to TC35

Void SendToTc35(unsigned char* p,unsigned char Long)

{

While(Long--)

{

SendASC(*p++);

}

}

// communication interrupt receiving program

Void Rs485_Do(void) interrupt 4 using 1

{

If(RI==l)

{

RI=0;

RsBuq[RsPoint++]=SBUF;

If fRsPoint》=sizeof(RsBuf))

{

RsPoint=0;//FlagRs485=0;

} //data processing

}

}

// Send AT connection command

Char code AT_Code[]=“OK”;

Void Send_AT(void)

{

Unsigned char *p;

While(1)

{

ClrRsBuf(RsBuf, sizeof(RsBuf));

SendToTc35(AT_Tc35,2); //"AT"

SendASC(OVER);

//************ Waiting for a response "ok"

ES=1; //must be interrupted

Delay(50);

P=strstr(RsBuf, AT_Code);

If(p!=NULL) break;

}

)

/ / Send bps connection command

Void Send_BPS(void)

{

SendToTc35(AT_Tc35,3); //"AT+"

SendToTc35(Bps_Tc35,sizeof(Bps_Tc35)-1);//"IPR=19200"

SendASC(OVER);

}

/ / Set the text

Void SetText(void)

{

SendToTc35(AT_Tc35,3); //"AT+"

SendToTc35(Text_tc35,sizeof(Text_tc35)-1);//"IPR=19200"

SendASC(OVER);

Delay (100):

/ / Delete the short message

Unsigned char EraseMsg(unsigned char index)

{

Unsigned char *p,i=20;

SendToTc35(AT_Tc35,3); //"AT+"

SendToTc35(Erase_Tc35,sizeof(Erase_Tc35)-1);//"IPR=19200"

SendASC(index);

SendASC(OVER);

ES=1;

While(i--)

{

Delay(200);

P=strstr(RsBuf, AT_Code);

If(P!=NULL) {return 1;}

}

Return 0;

}

/ / Read the short message

Char code Ask_No[]=”+CMGR:0,,0”;

Char code ERROR{]=”ERROR”;

Char code Ask_Tc35[]=”/”;

Unsigned char ReadMsg(unsigned char index)

{

Unsigned char *p,i;

Unsigned char Buf[40];

SendToTc35(AT_Tc35,3); //"AT+"

SendToTc35 (Read_Tc35, sizeof (Read_Tc35)-1);

SendASC(index);

SendASC(OVER);

ES=1; //must be interrupted

Delay (600);

/*-------

ES=0:

SendToTc35(RsBuf,99);

ES=1;

*/|

p=strstr(RsBuf, ERROR);

If(P!=NULL)

{

Send_AT();return 0;

p=strstr(RsBuf,Ask_No);//No information

If(p!=NULL)return 0;

p=strstr(RsBuf,Ask_Tc35);//20 bytes followed by MSG

If(p==NULL) return 0;

p=p+21;

For(i=0;i"sizeof(Buf);i++)

{

Buf[i]=*p++;

}

If(EraseMsg(index)==0) return 0;

p=strcpy(RsBuf,Buf); //Return RsBuf

Return 1;

)

/ / Send a short message

Char code SK[]=”》”;

Void SendMsgStart(void)

{

Unsigned char *p,i=10;

SendToTc35(AT_Tc35,3); //"AT+"

SendToTc35(Send_Tc35,sizeof(Send_Tc35)-1);//"IPR=19200"

SendASC(YinHao);

SendToTc35(Mp1.Hand,sizeof(Mp1.Hand)); //"AT+"

SendASC(YinHao);

SendASC(OVER);

ES=1;

While(i--)

{

Delay(100); //Get"""

p=strstr(RsBuf,SK);//"》"

If(p!=NULL)

{

ClrRsBuf(RsBuf, sizeof(RsBuf));

Delay(150); //Get"""

Break;

}

}

}

Hubungi kami

Author:

Ms. Zoe Zhong

Phone/WhatsApp:

+8618617178558

Produk populer
You may also like
Related Categories

Email ke pemasok ini

Subjek:
Ponsel:
Email:
Pesan:

Your message must be betwwen 20-8000 characters

Yetnorson Antenna Co., Ltd, didirikan pada 2010, adalah perusahaan profesional yang terlibat dalam penelitian, pengembangan, penjualan dan layanan antena komunikasi, Yetnorson memiliki spesialisasi dalam 2 g/3 g/4 g/wifi/antena TV, dan berbagai konektor RF dan rakitan kabel antena. Kami memiliki...
Newsletter
Alamat
Room #101,201,301,5BLDG , No.4 of XinWuCun New Area ,Shabo community Maluan Street Pingshan District, Shenzhen ,Guangdong , China, Shenzhen, Guangdong China

Hak cipta © 2024 Yetnorson Antenna Co., Ltd. semua hak dilindungi.

Hak cipta © 2024 Yetnorson Antenna Co., Ltd. semua hak dilindungi.

We will contact you immediately

Fill in more information so that we can get in touch with you faster

Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.

Kirim