Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] GSM sim900A interfacing with STM32F407

Status
Not open for further replies.

Ravindrakant Jha

Junior Member level 2
Joined
Nov 2, 2014
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Location
India
Activity points
274
Hello,
I am using STM32F407 discovery board for interfacing with GSM module,
I am getting a problem that when i send USART_puts("AT\r") commands then i get the response OK only for the first command ,the second command USART_puts("AT+CREG?\r")do no execute .
But if i send only single command USART_puts("AT+CREG?\r") then i get the response that can be seen on YAT terminal.

Secondly i made a function to send the command AT+CREG? and check response but that function is not returning 1 .


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
uint8_t GSM_AT_CREG(char *command)
{
 
     unsigned int urc_code=0;
     unsigned int ntwk_status=0;
     end_flag=0; //this flag i am using in receive interrupt
     
     USART_puts(&command[0]);
    
     while(end_flag!=1);
 
     urc_code=rx_buffer[7];//urc codes +CREG: 0[7],1[9]
     ntwk_status=rx_buffer[9];//network status
    
     if(urc_code==1 || urc_code==2 )
     {
         USART_puts("AT+CREG=0\r");  
     }
     if(ntwk_status == 1 || ntwk_status == 5)
     {
    //   
         return 1; 
     }  
}



Thanks in Advance
Ravindra Kant
 
Last edited by a moderator:

Are you using Serial Interrupt to receive the modem response ? If not then use it.. Also have you done proper voltage level translation between STM32's UART Tx pin and SIM900's Rx pin because STM32's Tx pin works at 3.3V and SIM900's Rx pin works at 2.8V. If you don't have voltage level translation then you will damage your modem.

If you have written Serial Interrupt code to receive the response then show ISR code.
 

Yes sir,I am using the Serial Interrupt to receive the modem response

[Code Snippet]

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void USART1_IRQHandler()
{   
 if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //it checks receive complete 
 {
    
     rx_web = USART_ReceiveData(USART1);
       Line_valid=1;
    
     if(rx_web == 0x0A || rx_web == 0x0D)  //receive ^M and ^J
         {
                count++;
             if(count==4)
             {end_flag=1;}
             }
     else if(rx_index1 < LINEMAX)
               {
         rx_buf_web[rx_index1++]=rx_web; //receiving main response
                         
         }
         
     }   
}



Secondly ,the module Rx Tx pin are on 3.3 V
 
Last edited by a moderator:

Have a UART buffer of size 300 bytes if you are reading SMS. Once data is received after issuing a AT command then wait for 2 seconds so that the whole response is received then in ISR set a flag when data is received. Check if this flag is true in while(1) loop. If true wait for 2 seconds so that all serial data is received. After that check what response is received. If response is correct then continue wityh the next command. If response received is not correct then re-issue the AT Command again and make three attempts if it fails repeatedly then reset the modem (using MCU pin) and then start sending AT Command.
 

thanks for the quick replies...
Delay routine was missed,now command response can be seen on the terminal,Current i got stuck with this issue,
I have made a function for AT+CREG? command to check its response and take necessary actions.
But this function stalls after USART_puts(&command[0]);
uint8_t GSM_AT_CREG(char *command)


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
    uint8_t cell_id=0;
    
//   char *response;
     unsigned int urc_code=0;
     unsigned int ntwk_status=0;
     
     USART_puts(&command[0]);
     Delay_sec(1000);
    
     if(end_flag)
     {
        end_flag=0;
        urc_code=rx_buf_web[7];//urc codes
      if(urc_code==1 || urc_code==2 )
       {
          USART_puts("AT+CREG=0\r");  //to put off URC_code
                  Delay_sec(1000);       
           }
          ntwk_status=rx_buf_web[9];//network status
         
         if(ntwk_status == 1 || ntwk_status == 5)
              {
                 cell_id=1;
            // end_flag=0;
             //Delay_sec(1000);
         }
         else if(ntwk_status == 2)
         {
             Delay_sec(1000);
             USART_puts("AT+CREG?\r");
             Delay_sec(1000);
             if(ntwk_status == 1 || ntwk_status == 5)
             {
                 cell_id=1;
                // end_flag=0;
             }
         }
         else if(ntwk_status == 0 || ntwk_status == 3 || ntwk_status == 4)
         {
             cell_id=0;
            // end_flag=0;
         }
   }
  return (cell_id);
 }



I think i am doing a mistake ,but unable to sort out??
Thanks !
 
Last edited by a moderator:

Use syntax tags to post the code and show your full code. I have to see serial ISR code.
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
void USART1_IRQHandler()
{   
 if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //it checks receive complete interrupt(USART_IT_RXNE) on USARTx
 {
    
     rx_web = USART_ReceiveData(USART1); //receiving data from usart 1
      
    
     if(rx_web == 0x0A || rx_web == 0x0D)  //counting ^m ^j with response
         {
                count++;
             if(count==4 || count ==2)
             end_flag=1;
             }
         else if(rx_index1 < LINEMAX)
         {
         rx_buf_web[rx_index1++]=rx_web; //exact response
                         
          }
     }   
}
void main()
{
  GPIOInitialize();  //gpio initialize
  UART_Initialize();//uart initlaize
  NVICInitialize();  // vectored interrupt controller
  TIMER_Initialize(); 
  InitializeLED(); //initialize led
    
    
    SysTick_Config(SystemCoreClock/1000); //normal clock is 168,000 
    
               if(GSM_AT_CREG("AT+CREG?\r")) //checking CREG response
        {
             GPIO_SetBits(GPIOD,GPIO_Pin_12); //led set
         Delay_sec(2000);
         GPIO_SetBits(GPIOD,GPIO_Pin_12);
        }
        
 
 while(1)
 {
    
    //__WFI();
    
     if (end_flag) // A new line has arrived      
    {
        end_flag=0;
         }
  }
uint8_t GSM_AT_CREG(char *command)
{
    uint8_t cell_id=0;  //network status flag
    
     unsigned int urc_code=0; //urc codes
     unsigned int ntwk_status=0; 
     
     USART_puts(&command[0]); //send command
     while(end_flag!=1);
     //Delay_sec(1000);
    
     if(end_flag)  //processing received data
     {
         end_flag=0;
       urc_code=rx_buf_web[7];
      if(urc_code==1 || urc_code==2 )
       {
          USART_puts("AT+CREG=0\r"); //setting urc_code 0 so that they should not disturb
                  while(end_flag!=1);
                 // Delay_sec(1000);
             end_flag=0;
           }
              ntwk_status=rx_buf_web[9];//network status
         
         if(ntwk_status == 1 || ntwk_status == 5)  //registered network
                 {
             cell_id=1;
            // end_flag=0;
             //Delay_sec(1000);
         }
         else if(ntwk_status == 2) //network searching
         {
             //Delay_sec(1000);
             USART_puts("AT+CREG?\r");while(end_flag!=1);
             Delay_sec(1000);
             end_flag=0;
             if(ntwk_status == 1 || ntwk_status == 5)
             {
                 cell_id=1;
                
             }
         }
     else if(ntwk_status == 0 || ntwk_status == 3 || ntwk_status == 4) //access denied                                 //not registerd not searching
         {
             cell_id=0;
            // end_flag=0;
         }
   }
  return (cell_id);

 

Code:
rx_buf_web[]
contains ascii characters and not integers.

In the if, elseif conditions you are checking with integer values.
 

Is
Code:
command[0]
a 2D array ? If yes, what id the content of
Code:
command[0]
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top