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.

Help regarding modem response

Status
Not open for further replies.
Joined
Dec 4, 2012
Messages
4,280
Helped
822
Reputation
1,654
Reaction score
791
Trophy points
1,393
Location
Bangalore, India
Activity points
0
I am trying to test the response for AT\r command given to my mobile. In real term it shows response as AT\r\n\rOK\n\r. I tried to compare the received string with stored string but it didn't work, so I tried to print the integer values I get after subtracting 0x30 from each character in the response buffer and I get the following values.

17 A
36 T
-35 CR
-38 LF
31 O
27 K
-35 CR
-38 LF

I am assuming -35 as \r and -38 as \n but still I can't check the response with the stored string. What the real term is showing is different from what I am getting on LCD. How to conform the response character sequence?

I am attaching the RealTerm showing the response.
 

Attachments

  • atresponse.png
    atresponse.png
    7.1 KB · Views: 65

@Jayanth,

Whenever you issue a command to the modem followed by ENTER, the modem will always return "\r\nOK\r\n"...

This is the standard output from any module..

When you are trying to print the received string, remove "\r\n" from either sides of the response and print..

Then it will be fine..
 
I am not using SIm900 or other modem for this particular purpose. I am using my mobile and I printed the int values of the responses on LCD and figured out the response sequence. The first response check is passing but the 2nd and 3rd response checks are not passing.

1st response

17 A
36 T
-35 \r
-35 \r
-38 \n
31 O
27 K
-35 CR
-38 LF

2nd response

17 A
36 T
-5 +
19 C
29 M
23 G
22 F
13 =
1 1
-35 \r
-35 \r
-38 \n
31 O
27 K
-35 \r
-38 \n

3rd response

17 A
36 T
-5 +
19 C
29 M
23 G
35 S
13 =
-14 "
0795982726
-14 "
-16 ' '
-16 ' '
-16 ' '
-3 -
-3 -
3 3
 

@Jayath

Mobile is also a modem..

Anyways seeing the 1st and 2nd command & its response its correct & fine..

"The first response check is passing but the 2nd and 3rd response checks are not passing." --- I dont understand the meaning of this...

For the 3rd command:

1. The mobile number is not 10 digit excluding the 0
2. At the last after the quotes, ENTER is not given..
 
The commands sent are AT\r, AT+CMGF=1\r, and AT+CMGS="number"\r and the responses are as above. The response check for AT\r is passing but not for the other two.


I am attaching my project files.
 

Attachments

  • UART SMS.rar
    55.6 KB · Views: 46
Last edited:

@Jayanth,

See the 2nd command carefully, if it is not passing then you will not get the response as "\r\nOK\r\n...This means that the command is passed...

For the 3rd command not passing it is the reason i told in my earlier reply...check it again..
 
I checked and confirm that UART is not hanging. I have posted by code in my last post. The code to display int values of gsm response is commented out. I don't know why 2nd and 3rd response checks are failing. buffer is filled properly as I am printing the response on LCD.
 

@Jayanth,

char response2[] = "AT+CMFG=1\r\r\nOK\r\n"; //You have to check for AT+CMGF instead of AT+CMFG
char response3[] = "AT+CMFS=0795982726 > "; //You have to check for AT+CMGS instead of AT+CMFS

Pls check the number it is only 9 digit excluding 0...
 
@Jayanth,

I had told you earlier, since the number u mentioned "0795982726" ---> this is only 9 digits excluding the '0'...

It should be a 10 digit mobile number rite excluding the '0'...

And the response you checked is also wrong...

It should be char response3[] = "AT+CMGS=\"0795982726\"\r\r\n>"; ---> the number should be 11 digit inclusive of '0'
 
Yes. I found that. Now the last step is giving the problem. The message index changes everytime. I have to write some code so that the program keeps track of sent message index.

Here is the 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
 
void USART_Init(void);
void USART_Write(unsigned char x);
void USART_Write_Text(char *z);
 
char AT[] = "AT\r";
char CMGF[] = "AT+CMGF=1\r";
char CMGS[] = "AT+CMGS=\"0795982726\"\r";     //0795982726
char msg[] = "Hi EDABoard";
char buff[25], i = 0, mystr[17];
char response1[] = "AT\r\r\nOK\r\n";
char response2[] = "AT+CMGF=1\r\r\nOK\r\n";
char response3[] = "AT+CMGS=\"0795982726\"\r\r\n> ";
char response4[] = "+CMGS: 170\r\r\nOK\r\n";
int dummy;
 
void USART_init(void){
        TXSTA = 0x22; // low speed communication, asynchronous, Tx enable, 8 bit data
        RCSTA = 0x90;// serial port enable, 8 bit data, continuous Rx, no address detection
        SPBRG = 12;//9600 bps
        TRISC = 0x80; //RC7 is Rx while RC6 is Tx
        INTCON = 0xC0; // GIE and PEIE
}
 
void USART_Write(char x){
        while(!TRMT_bit);  // wait for previous transmission to finish
        TXREG = x;
 
}
 
void USART_Write_Text(char *z){
        while(*z)USART_Write(*z++);
}
 
void clearBuffer(){
     for(i = 0; i < 25; i++)buff[i] = '\0';
 
}
 
void checkChars(){
      while(buff[i] != '\0'){
           dummy = buff[i] - 0x30;
           //if(dummy < 0) dummy = dummy + 48;
           IntToStr(dummy, mystr);
           LCD_Out(2,1,myStr);
           Delay_ms(3000);
           LCD_Out(2,1,"      ");
           Delay_ms(2000);
           i++;
      }
      i = 0;
 
 
}
 
void Interrupt(){
      if(RCIF_bit){
             //if(OERR_bit){
                   //CREN_bit = 0;
                   //CREN_bit = 1;
                   //OERR_bit = 0;
             
             //}
             buff[i++] = RCREG;
             buff[i] = '\0';
             
      
      }
      
      RCIF_bit = 0;
 
}
 
void main() {
 
        TRISA = 0xFF;
        TRISB = 0x00;
        PORTB = 0x00;
        
        USART_Init();
        Delay_ms(200);
        
        CREN_bit = 1;
        RCIE_bit = 1;
        Lcd_Init();                        // Initialize LCD
        Lcd_Cmd(_LCD_CLEAR);               // Clear display
        Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
        LCD_Out(1,1,"Hello");
        
        while(1){
        
                  while(strcmp(buff, response1) != 0){
                      USART_Write_Text(AT);
                      Delay_ms(1000);
                      i = 0;
                      //checkChars();
                  }
                  clearBuffer();
                  i = 0;
                  while(strcmp(buff, response2) != 0){
                      USART_Write_Text(CMGF);
                      Delay_ms(2000);
                      i = 0;
                      //checkChars();
 
                  }
                  clearBuffer();
                  i = 0;
                  while(strcmp(buff, response3) != 0){
                      USART_Write_Text(CMGS);
                      Delay_ms(2000);
                      i =0;
                      //checkChars();
 
                  }
                  clearBuffer();
                  i = 0;
                  //while(strcmp(buff, response4) != 0){
                          USART_Write_Text(msg);
                          USART_Write(0x1A);
                          Delay_ms(5000);
                          i =0;
                  //}
                  clearBuffer();
                  i = 0;
        }
}

 

@Jayanth,

Do not worry about sent message index. As nobody would be interested in the sent message index.

What you can do is instead of checking for sent message index along with OK, you check only for "OK"..

But before you get OK, you will get the message index which you are already capturing in the buffer. And hence throw the buffer output directly..

char response4[] = "+CMGS: 170\r\r\nOK\r\n"; ----> Instead of this way of checking use the below method..

char response4[] = "\r\nOK\r\n";----> use this way...your problem is solved...never worry about sent message index...
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top