Research on GPRS Data Transmission Technology Based on STM32 Microprocessor

This paper introduces the main underlying configuration of STM32 through the research on the underlying configuration and data transmission of STM32, and focuses on the implementation of data transmission. Explain the details and precautions for implementing data transfer through the introduction of the source code of the key steps. The method has certain realization value and reference value for other projects or chips, and is simple and reliable, universal and versatile.

1, STM32 bottom layer configuration

In order to realize the transmission of data commands between STM32 MCU and SIM900A module, this article takes the serial port as an example, first builds the development platform, adds the corresponding library function and configuration file in the project, and then configures the clock and the corresponding input and output GPIO interface of the serial port. At the same time of configuration, you need to write your own schematic diagram to ensure the correct configuration. In this way, the basic development platform is built.

1.1, serial port configuration

After the development platform is built, the serial port can be configured. The configuration rate is 115200b/s, the word length is 8bit, the 1bit stop bit, the serial port mode is the input and output mode, and finally, the corresponding serial port is initialized. After initializing the serial port, open the interrupt response function of the serial port, that is, USART_ITConfig (USART2, USART_IT_RXNE, ENABLE) (take serial port 2 as an example), and then enable the corresponding serial port, so that the serial port function is basically configured. It should be noted that some programs may lose the first place during transmission. This issue relates to the mechanism of the USART. After the hardware reset, the status bit of the USART is set (set to 1, indicating that it has been sent), and the data can be sent normally. When a frame of data is transmitted, the bit is set by hardware. Clearing the TC bit (set to 0) is done by software. This bit is cleared by first reading USART_SR and then writing USART_DR. However, when the first frame data is sent, the program does not read USART_SR, but directly writes USART_DR, so the TC flag is still set and is not cleared. After the first frame data is sent, the status returned by USART_GetFlagStatus() is sent, and the program will immediately send the next frame data, so the first frame data will be overwritten by the second frame data, so that it will not be seen. To the first data. Depending on the situation, the transfer completion flag, USART_ClearFlag(USART2, USART_FLAG_TC), can be cleared before or after each transfer.

1.2, interrupt configuration

After configuring the serial port, the NVIC will be configured. Configure the interrupt packet for the first time, then select the serial port interrupt, which is NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn (mainly defined by the firmware library used).

Set the preemptive interrupt priority and the reactive interrupt priority level, then enable interrupts and initialization. The above configuration must be combined with its own situation to design the optimal interrupt grouping and priority to ensure the speed of the program response to the interruption. What is done after the interrupt is configured in the stm32f10x_it.c file, which is explained in more detail below.

2, the implementation details

The principle of implementing GPRS data transmission is: STM32 parses a string of data or commands, and then sends them to the SIM900A module by character or character by serial port or other means. After receiving the data, SIM900A sends the data to the server through the SIM card. When the SIM900A receives the data, it immediately responds to the interrupt and performs data processing in the manner set by the interrupt. At this point, it is necessary to control the transmission of data by sending a check and receiving a check.

2.1, send inspection

Since the STM32 sends data to the SIM900A module character by character, the correctness and consistency of the data must be guaranteed. If the response is interrupted or task scheduling is sent at the time of transmission, the transmission will be invalidated, causing the program to go wrong, so the developer must be wary of this type of error.

When sending data or commands, the data can be passed to the sending function through parameters, which are controlled by the sending function. After the sending is completed, a sending completion flag is returned to inform the calling function that the sending has been completed. The source program is as follows:

voidUSART_Send_Byte(charMyData){//send character function

USART_ClearFlag(USART2, USART_FLAG_TC);

/ / Clear the flag bit, as described above

USART_SendData (USART2, MyData); / / send data

While(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET);//waiting to send complete

}

voidUSART_Send_Str(char*s){//send string

inTI;

Intlen=strlen(s)-1;//string length

For(inTI=0;i"len;i++)

USART_Send_Byte(s[i]);//Cycle sends the string

If(s[i]==0x0a){//determine whether the transmission is over

SendCFFlag=TRUE;

/ / If true, the send completion flag is true

}else{

USART_Send_Byte(s[i]);//If it is false, send it out

}

}

2.2, receiving inspection

When the SIM900A has data returned or data is received by the SIM900A to the lower computer, the STM32 will immediately respond to the interrupt to receive data. At this point, a series of processing is performed in the interrupt function. Taking SIM900A as an example, the commands returned by the SIM900A module end with "r" + "n" + "", so the end of the test transmission can be judged according to it. The USART2_IRQHandler function in the interrupt response function (ie stm32f10x_it.c file) can be set as follows:

voidUSART2_IRQHandler(void)

{

If(USART_GeTITStatus(USART2,USART_IT_RXNE)!=RESET){

/ / Store the received characters into the receive buffer RxBuffer

RxBuffer[ReceCounter++]=(char)USART_ReceiveData(USART2);

/ / Determine whether the end of the reception

If(RxBuffer[ReceCounter]=="&&RxBuffer[ReceCounter-1]==0x0A&&

RxBuffer[ReceCounter-2]==0x0D){

ReceCFFlag=TRUE;

}

USART_ClearITPendingBit(USART2, USART_IT_RXNE);

}

}

The basic idea of ​​this function is to store the characters received by the USART into the buffer one by one, and then determine whether the last three characters of the buffer are the end identifier of SIM900A. If false, continue receiving; if true, the Receive Complete Identifier is set to true. When the reception completion identifier is true, the reception is completed, and then the data processing can be performed.

2.3, command function implementation method

The following will take AT+CIPSEND as an example to illustrate the details of sending data. After initializing the module, opening the network, establishing an access point, and establishing a TCP connection, you can start sending data. The implementation source code is as follows:

u8GPRS_Send(void){

U8i=0;

U8*p;

USART_SendToGPRS ("AT+CIPSENDrn"); / / send command

Delay_ms (500); / / delay 500ms

P=LookFor_Str(RxBuffer, """);

/ / Find if there is a "" symbol, if there is, you can send data

If(p!=0){

p=0;

Memset (RxBuffer, 0, BufferSize); / / clear the receive buffer

USART_SendToGPRS (GPRSSendData); / / send data

Delay_ms(500);

Delay_ms(500);

Delay_ms(500);

p=LookFor_Str(RxBuffer, "SENDOK");

If(p!=0){//Judge whether the transmission is successful

/ / Send a successful operation

Return1;

}else{

/ / Send failed operation

Return0;

}

}

}

The basic idea of ​​this function is to first send a command and then find out if there is a "" symbol, if it is, then you can start sending data. After a delay, look for the receiving buffer to see if there is a "SENDOK" word. If there is a message, the transmission is successful. If not, it indicates that the transmission failed. Further operations can be made based on the judgment. For details on the usage of the commands, see the AT command manual for the SIM900A. There are three points to note:

(1) In this test program, you need to obtain IP before you can establish a TCP connection, which is determined by the SIM900A mechanism. Therefore, if the developer cannot establish a TCP connection, in addition to testing whether the network is normal and the server is properly configured, the IP address must be obtained first in the program, and the command is AT+CIFSR.

(2) The status of SIM900A can be obtained first, and the command is AT+CIPSTATUS. Determining which operations to perform based on the state can reduce the amount of operation and simplify the code, thereby reducing run time and improving operational efficiency. See the AT command manual for the SIM900A for details.

(3) The setting of the delay requires specific analysis of specific problems. For example, when the SIM900A module is initialized, it only takes 500ms to delay, and the information returned by the module is received. When receiving the information from the server, sometimes the signal problem or the huge amount of data may be delayed for a long time. Developers are required to test on their own. The accurate setting of the delay can reduce the delay time while ensuring the correctness of the data, thereby improving the operating efficiency of the program.

3. Conclusion

This paper explains the configuration of the STM32 microprocessor underlying the STM32 microprocessor serial port configuration and interrupt configuration, and then realizes the GPRS data transmission technology through the SIM900A sending and receiving data, thus realizing the STM32 microprocessor to access the Internet. In the receiving verification implementation, the judgment can be made only once according to whether the reception is completed, thereby reducing the interruption running time. SIM900A is a GSM/GPRS dual-band module. It can also realize many functions such as calling, sending and receiving text messages, HTTP and FTP transmission. Through more in-depth research, it can maximize the practical value of the module, thus providing more electronic products. More application features.

Bimetal Thermometer

Bimetallic thermometer combines two metals with different linear expansion coefficients, and one end is fixed. When the temperature changes, the thermal expansion of the two metals is different, which drives the pointer to deflect to indicate the temperature. This is bimetallic sheet thermometer, as shown in the figure on the above page. The temperature measurement range is - 80 ~ 500C, which is suitable for temperature measurement when the accuracy requirement is not high in industry. As a temperature sensing element, bimetallic sheet can also be used for automatic temperature control.

Pressure Type Thermometer6

Bimetal Thermometer,Marine Bimetal Thermometer,Bimetallic Thermometer For Marine Pipeline,Bimetallic Thermostat Thermometer

Taizhou Jiabo Instrument Technology Co., Ltd. , https://www.jbcbyq.com