Research on GPRS data transmission technology based on STM32 microprocessor

Publisher:SparklingSoulLatest update time:2013-02-04 Source: 21IC Keywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

STM32 is one of the mainstream products based on the ARM Cortex-M3 core launched by STMicroelectronics (ST). It is designed by ST specifically for embedded applications that require high performance, low power consumption and low cost. It has been widely used in various fields. SIM900A is a compact GSM/GPRS dual-band module product promoted by SIMCom. It is favored by engineers for its stable performance, exquisite appearance and high cost performance.
 This article introduces the main underlying configuration of STM32 through the study of STM32 underlying configuration and data transmission, and focuses on the implementation of data transmission. Through the introduction of the program source code of the key steps, the details and precautions of implementing data transmission are explained. This method has certain implementation value and reference value for other projects or chips, and it is simple, reliable, universal and general.
1 STM32 underlying configuration
 In order to realize the transmission of data commands between the STM32 microcontroller and the SIM900A module, this article takes the serial port as an example, first builds a development platform, adds corresponding library functions and configuration files to the project, and then configures the clock and the corresponding input and output GPIO interface of the serial port. During configuration, you need to write according to your own schematic diagram to ensure that the configuration is correct. In this way, the basic development platform is built.
1.1 Serial port configuration
 After the development platform is built, you can configure the serial port. Configure the rate to 115 200 b/s, the word length to 8 bits, 1 bit stop bit, the serial port mode to input and output mode, and finally initialize the corresponding serial port. After initializing the serial port, open the interrupt response function of the serial port, that is, USART_ITConfig (USART2, USART_IT_RXNE, ENABLE) (taking 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 bit during transmission. This problem involves the mechanism of USART. After the hardware is reset, the status bit of USART is set (set to 1, indicating that it has been sent), and the data can be sent normally at this time. When a frame of data is sent, the hardware sets this bit. The TC bit is cleared (set to 0) by software, which is cleared by reading USART_SR first and then writing USART_DR. However, when the program sends the first frame of data, it does not read USART_SR, but directly writes USART_DR, so the TC flag is still set to 1 and is not cleared. After sending the first frame of data, the status returned by USART_GetFlagStatus() is that the transmission is complete, and the program will immediately send the next frame of data, so the first frame of data will be overwritten by the second frame of data, so the first data cannot be seen. According to this situation, the transmission completion flag can be cleared before or after each transmission, that is, USART_ClearFlag (USART2, USART_FLAG_TC).
1.2 Interrupt configuration
 After configuring the serial port, NVIC will be configured. First configure the interrupt group, and then select the interrupt of the serial port, that is, NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn (based on the definition of the firmware library used).
Then set the preemptive interrupt priority and responsive interrupt priority, and then enable interrupts and initialize. 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 responding to the interrupt. The content done after the interrupt is configured in the stm32f10x_it.c file, which will be explained in detail below.
2 Implementation details
 The principle of implementing GPRS data transmission is: STM32 parses a string of data or commands, and then sends it to the SIM900A module character by character through the serial port or other means. After SIM900A receives the data, it sends it to the server through the SIM card. When SIM900A receives the data, it immediately responds to the interrupt and processes the data according to the method set by the interrupt. At this time, it is necessary to control the transmission of data through the sending check and receiving check.
2.1 Sending check
 Since STM32 sends data to the SIM900A module character by character, the correctness and coherence of the data must be guaranteed. If you respond to the interrupt or perform task scheduling during the sending, the sending will be invalid, resulting in program errors, so developers must be vigilant against such errors.
 When sending data or commands, the data can be passed to the sending function through parameters, which will be controlled uniformly by the sending function. After the sending is completed, a sending completion flag will be returned to inform the caller of the function that the sending is completed. The source program is as follows:
 void USART_Send_Byte(char MyData){ //Send character function
 USART_ClearFlag(USART2, USART_FLAG_TC);
 //Clear flag bit, as mentioned above
USART_SendData(USART2, MyData); //Send data
while(USART_GetFlagStatus(USART2, USART_FLAG_TC)==RESET); //Wait for sending to complete
}
void USART_Send_Str(char*s){ //Send string
 int i;
 int len ​​= strlen(s)-1; //String length
for(int i=0; iUSART_Send_Byte(s[i]); //Loop to send the string
if(s[i]==0x0a){ //Judge whether the sending is completed
SendCFFlag=TRUE;
//If true, the sending completion flag position is true
}else{
USART_Send_Byte(s[i]); //If false, send it out
}
}[page]
2.2 Receiving verification
 When SIM900A returns data or data is received by SIM900A to the lower computer, STM32 will immediately respond to the interrupt to receive the data. At this time, a series of processing must be performed in the interrupt function. Taking SIM900A as an example, the commands returned by the SIM900A module all end with "r"+"n"+"", so the end of the transmission can be judged based on it. In the interrupt response function (i.e. in the stm32f10x_it.c file), the USART2_IRQHandler function can be set as follows:
void USART2_IRQHandler(void)
{
if(USART_GetITStatus(USART2, USART_IT_RXNE)!=RESET){
//Store the received characters in the receive buffer RxBuffer
RxBuffer[ReceCounter++]=(char)USART_ReceiveData(USART2);
//Judge whether the reception is completed
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: store the characters received by USART into the buffer one by one, and then determine whether the last 3 characters in the buffer are the end identifier of SIM900A. If it is false, continue to receive; if it is true, set the receive completion identifier to true. When the receive completion identifier is true, it means that the reception is completed, and then data processing can be performed.
2.3 Command function implementation method
 The following will take AT+CIPSEND as an example to explain 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:
u8 GPRS_Send(void){
u8 i=0;
u8*p;
USART_SendToGPRS("AT+CIPSENDrn");//Send command
Delay_ms(500);//Delay 500 ms
p=LookFor_Str(RxBuffer,">");
//Check whether there is ">" symbol. If so, you can send dataif
(p!=0){
p=0;
memset(RxBuffer,0,BufferSize);//Clear receive bufferUSART_SendToGPRS
(GPRSSendData);//Send data
Delay_ms(500);
 Delay_ms(500);
 Delay_ms(500);
 p=LookFor_Str(RxBuffer,"SEND OK");
if(p!=0){//Judge whether the sending is successful
//Sending successful operation
 return 1;
}else {
//Sending failed operation
   return 0;
  }
   }
}

 


 The basic idea of ​​this function is: first send the command, then check whether there is a ">" symbol. If there is, it means that data can be sent. After a delay, check whether there is the word "SEND OK" in the receiving buffer. If there is, it means that the sending is successful, otherwise it means that the sending failed. Further operations can be performed based on the judgment. For detailed usage of the command, please refer to the AT command manual supporting SIM900A. There are three points to note:
 (1) In the test program of this article, it is necessary to obtain the IP before establishing a TCP connection. This 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 whether the server is correctly configured, it is also necessary to obtain the IP in the program first. The command is AT+CIFSR.
 (2) You can first obtain the status of SIM900A. The command is AT+CIPSTATUS. Determining which operations to perform based on the status can reduce the amount of running, simplify the code, thereby reducing the running time and improving the running efficiency. For details, please refer to the AT command manual supporting SIM900A.
 (3) The setting of the delay requires specific analysis of specific problems. For example, when initializing the SIM900A module, it only takes 500 ms to delay the information returned by the module. When receiving information from the server, sometimes it may take a longer delay due to signal problems or huge amounts of data, and developers need to test it themselves. Accurate delay setting can reduce the delay time while ensuring data correctness, thereby improving the running efficiency of the program.
 This article explains the underlying configuration of the STM32 microprocessor by setting the serial port of the STM32 microprocessor and configuring the interrupt, and then implements the GPRS data transmission technology through the sending and receiving data of SIM900A, thereby enabling the STM32 microprocessor to access the Internet. In the implementation of the reception test, only one judgment can be made based on whether the reception is completed, thereby reducing the interrupt running time. SIM900A is a GSM/GPRS dual-band module, which can also realize many functions such as calling, sending and receiving text messages, HTTP and FTP transmission, etc. Through more in-depth research, the practical value of the module can be maximized, thereby providing more application functions for electronic products.

Keywords:STM32 Reference address:Research on GPRS data transmission technology based on STM32 microprocessor

Previous article:Design of STM32 debugging platform based on LabVIEW
Next article:Design of portable mobile phone Bluetooth attendance machine system based on STM32

Recommended ReadingLatest update time:2024-11-16 22:32

(II) Interrupt configuration of stm32
1. Interrupts and exceptions of stm32   Cortex has a powerful exception response system, which can interrupt the current code execution process. Events are divided into exceptions and interrupts, which are managed in a table. Numbers 0 to 15 are kernel exceptions, and 16 and above are external interrupts. This table i
[Microcontroller]
(II) Interrupt configuration of stm32
STM32 clock configuration and related issues
Ⅰ. Write in front Recently, many friends have asked: 1. The data printed out by my USART serial port is garbled? 2. My TIM timer delay or timing is inaccurate?   Common possible causes: 1. Crystal oscillator problem: The external crystal oscillator does not oscillate, or the frequency does not match the configuration.
[Microcontroller]
STM32 clock configuration and related issues
Solar LED Street Light Solution Based on STM32 MCU
As fossil energy is decreasing and the problem of global warming caused by excessive greenhouse gas emissions is becoming more and more important, people are actively developing various types of renewable energy on the one hand, and advocating green environmental protection technologies for energy conservation and emis
[Power Management]
Solar LED Street Light Solution Based on STM32 MCU
STM32 USART using parity bit
When there is no check bit, the data bit is usually 8 bits. When using the parity bit, the data bit should be set to 9. A parity bit is also included with the data bits. See the reference manual for details:
[Microcontroller]
STM32 USART using parity bit
NEC infrared encoding and decoding based on STM32
NEC infrared remote control protocol The NEC protocol uses pulse distance encoding of thebits. Each pulse is a 560µs long 38kHz carrier burst (about 21 cycles). Alogical "1" takes 2.25ms to transmit, while a logical "0"is only half of that, being 1.125ms. The recommended carrier duty-cycle is 1/4or 1/3.  The frequen
[Microcontroller]
NEC infrared encoding and decoding based on STM32
Understanding the operation of STM32 bit band
    With the support of bit operations in the Cortex-M3, single bits can be read and written using normal load/store instructions.   In the bit-banding supported by the CM3, bit-banding is implemented in two regions.   One is the lowest 1MB range of the SRAM region, 0x20000000 ‐ 0x200FFFFF (the lowest 1MB in the SRAM
[Microcontroller]
C language STM32 absolute value function
  Function name: abs   Function: Find the absolute value of an integer   Header file: math.h   Function prototype: int abs(int i);   Program example:   #include stdio.h   #include math.h   int main(void)   {   int number = -1234;   printf("number: %d absolute value: %d\n", number, abs(number));   r
[Microcontroller]
About the remapping of STM32 interrupt vector table
1 Why do we need to remap the interrupt vector table?               The COREM3 authoritative guide says "However, in order to dynamically redistribute interrupts, CM3 allows vector table relocation - locating each exception vector starting from another address.    The area corresponding to these addresses can be the c
[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号