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.

Using 18f452 send/ receive sms to GSM A900 , mikroC

Status
Not open for further replies.

SyedFahad

Junior Member level 1
Joined
Jul 5, 2014
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
116
This is the part of sending sms code , help me in correcting this. Thanks

Code:
UART1_Init(9600);      // Initialize UART module at 9600 bps
  Delay_ms(100);
  
        
  UART1_Write(2);
  UART1_Write(13);
  UART1_Write_Text("AT+CMGS="); 
  Delay_ms(1000);

 
  UART1_Write(0x22);              // double qoute
  Delay_ms(2000);

  UART1_Write_Text("9800220107"); // Telephone Number 
  cd_chr_cp(uart_rd);
  UART1_Write(0x22);              // double qoute
  UART1_Write(0x0D);              // mean Enter

  UART1_Write(0x22);   
  UART1_Write_Text("Wasti");     //My Text Test
  UART1_Write(0x22);             // double qoute
  Delay_ms(2000);

  UART1_Write(26);                //Ctr +Z
  Delay_ms(2000);
  UART1_Write(0x0D);             // mean Enter
  Delay_ms(2000);
 
Last edited by a moderator:

0x1A is same as 26 in decimal.

Are you sure that you don't need a delay between UART1_Write(2) and UART1_Write(13)
 

Hi, Try this 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
void main() {
 
 //Set UART Tx and Rx pins as input pins here using TRISx   
    
 UART1_Init(9600);      // Initialize UART module at 9600 bps
 Delay_ms(100); 
        
 while(1) {
 
    UART1_Write_Text("AT\r");  
    Delay_ms(2000);
    UART1_Write_Text("AT+CMGS=1\r"); 
    Delay_ms(2000);
    UART1_Write_Text("AT+CMGS=\"9800220107\"\r");
    Delay_ms(3000);
    UART1_Write_Text("Wasti");
    UART1_Write(26);                
    Delay_ms(6000);
  }
 
}

 

I didn't used 0X1A,
I think i am not using correct command format for sms sending.

- - - Updated - - -

I am also having trouble in receiving the sms on sim module. Help me using AT+CMGR command . Thanks

- - - Updated - - -

You are using AT+CMGS and mob number together. I will try this code. Can yiu further explain how to receive the sms at sim module A900. How to use AT+CMGR cammand. Thanks

- - - Updated - - -

Please help me in using AT+CMGR command for receiving sms at A900 module. Thanks

Hi, Try this 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
void main() {
 
 //Set UART Tx and Rx pins as input pins here using TRISx   
    
 UART1_Init(9600);      // Initialize UART module at 9600 bps
 Delay_ms(100); 
        
 while(1) {
 
    UART1_Write_Text("AT\r");  
    Delay_ms(2000);
    UART1_Write_Text("AT+CMGS=1\r"); 
    Delay_ms(2000);
    UART1_Write_Text("AT+CMGS=\"9800220107\"\r");
    Delay_ms(3000);
    UART1_Write_Text("Wasti");
    UART1_Write(26);                
    Delay_ms(6000);
  }
 
}


I will try the above code for sending sms. Now i am facing trouble in receiving sms at module A900. Help me how to use this cmgr FOR RECEIVING.
 
Last edited by a moderator:

hi,when a sms is recieved it gives the response as +cmti=D,where D iss any message storage number
then use the command at+cmgr=D.....u can read unread sms
 

What command should i use after AT+cmgr.
i.e If i want to show sms on LCD display.
Please tell .
 

hi, u first connect ur modem through rs232 in pc.open hyperterminal type the command at+cmgr=1 supposethen u will see that the response would be date ,time, mobile number of sender and then the message
so whenever u r writing at+cmgr=4 whatever set ur microcontroller in recieve mode i.e clear recieve flag and after 40 times recieving u will get ur message...
 

Thanks for reply Tanmay Dash,
Actually i am making a project to turn a load ON and OFF (eg. A fan ). I have made complete hardware including, power supplies, interfacing of lcd, sim module. Also i am succesful to send sms, but i am hving difficulty in receiving sms. I am just trying to READ sms and show it on LCD, so that i will be satisfied that i am able to receive sms. Can you help me in CODE to display it on LCD. This is the latest part of my code including, sms sending and showing it on LCD and it is working:

Code:
(This is just the part of my code. Some part is missing here.)


void main()
{
 
 LCD_Init();
 Lcd_Cmd(_LCD_CLEAR);
 
 UART1_Init(9600);
 UART1_Write_Text("ATE0");
 UART1_Write(13);
 UART1_Write(10);
 Delay_ms(1500);

 UART1_Write_Text("AT+CMGF=1");            
 UART1_Write(13);
         UART1_Write(10);
         Delay_ms(1500);

  while(1){
 UART1_Write_Text("AT+CMGS=") ;
  Delay_ms(500);
 UART1_Write_Text("\"+9231234567\"");
 Lcd_Out(2,1,"031234567");
 UART1_Write(13);
 UART1_Write(10);
 Delay_ms(1500);

 Lcd_Cmd(_LCD_CLEAR);

 UART1_Write_Text("HI HELLO");
 Lcd_Out(2,1,"HI HELLO");
 UART1_Write(26) ;
 Delay_ms(1500);

 }
 }
 

Zip and attach your mikroC Project files. I will add the code to receive SMS. Also post screenshot showing SIM900 response for AT+CMGR=x\r

x can be any index value. It will be usually 0 to 25 for SIM memory.
 

Zip and attach your mikroC Project files. I will add the code to receive SMS. Also post screenshot showing SIM900 response for AT+CMGR=x\r

x can be any index value. It will be usually 0 to 25 for SIM memory.

Ok i will try to upload.
I am uploading again sending part, with lcd interfacing.
I just want to show received sms on LCD. Nothing else.
Because i will do the controlling (Turn ON/OFF) part after i received the sms. Thanks

Code:
// Lcd pinout settings
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

// Pin direction
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

void main()
{
 TRISD = 0;
 TRISC = 0;
 PORTD=0 ;
 LCD_Init();
 Lcd_Cmd(_LCD_CLEAR);
 UART1_Init(9600);
 Lcd_Out(1,1,"Hello");
 UART1_Write_Text("ATE0");
  Lcd_Out(2,1,"ATE0");
 UART1_Write(13);
 UART1_Write(10);
 Delay_ms(1500);
           Lcd_Cmd(_LCD_CLEAR);
         UART1_Write_Text("AT+CMGF=1");
          Lcd_Out(2,1,"AT+CMGF=1");
         UART1_Write(13);
         UART1_Write(10);
         Delay_ms(1500);
         Lcd_Cmd(_LCD_CLEAR);
  while(1){
 UART1_Write_Text("AT+CMGS=") ;
  Lcd_Out(2,1,"AT+CMGS=");
  Delay_ms(500);
 UART1_Write_Text("\"+92331234567\"");
 Lcd_Out(2,1,"0331234567");
 UART1_Write(13);
 UART1_Write(10);
 Delay_ms(1500);
    Lcd_Cmd(_LCD_CLEAR);
 UART1_Write_Text("HI HELLO");
   Lcd_Out(2,1,"HI HELLO");
 UART1_Write(26) ;
 Delay_ms(1500);

 }
 }

This is working !!
 

Hi I hv started working on receiving part.

I am observing every step of my working code. When I started to check +CMTI.

It confirms '+'
then 'C'

But it stops after 'C' and did not proceed further.

(Because it should read complete +CMTI so that i can save the slot number.)

Please Help.
 

Zip and attach the mikroC Project files so that receiving code can be added to it. While(1) is missing.
 
Last edited:

hi Syed ,
i had a working code for recieving the sms.i can send the code to u but it wuld be better if u try for urself. here i can help .u wll get this response when a sms is recieved +cmti: "sm",?. the "?" is the memory storage number. after recieving store the memory number in memory.then type AT+CMGR=?.U can recieve the sms. code uploading is not allowed in edaboard site.so try the above steps u wll surely get the output .best of luck
 

I have same problem in receiving message, can anybody help me
 

@ aviraje8

The only way anyone could help you is if you post your code and circuit.

Otherwise your request for help as posted is the same as asking "How long is piece of string".

Cheers.
 


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
signed char sms_in[95];
bit flag;
char i=0;
void interrupt()
 {
  if (PIR1.RCIF==1)
  {
    if (UART1_Data_Ready())
   {
    sms_in[i] = UART1_Read();
    i++;
    if(i==88)
    {
   flag=1;
    }
 
Suppose I received message like "+CMGR: \"REC UNREAD\",\"+919325457889\",\"\",\"2014/12/27 17:04:02+22\"\r\nONN\r\nOK\r\n";
 
Then led should be ON
 
& when message received like "+CMGR: \"REC UNREAD\",\"+919325457889\",\"\",\"2014/12/27 17:04:02+22\"\r\nOFF\r\nOK\r\n"; 
 
Then led should be OFF 
 
   }
 
  }
}
 
void main()
{
     INTCON.GIE = 1;
     INTCON.PEIE = 1;
     PIE1.RCIE=1;
 
     TRISC5_bit = 0;
     UART1_Init(9600);
     Delay_ms(500);
     UART1_Write_Text("AT");
     Delay_ms(1000);
UART1_Write_Text("AT+CMGF=1");
     Delay_ms(1000);
UART1_Write_Text("AT+CMGR=1");
     Delay_ms(1000);
 
while(1)
{
 
if(flag==1)
     {
    char q=79;
    if(sms_in[q]=='A'&& sms_in[q+1]=='R'&& sms_in[q+2]=='T')
    {
     RC5_bit=1;
     UART1_Write(0X0D);
     UART1_Write(0X0A);
     flag=0;
      i=0;
    }
 
    else if(sms_in[q]=='O'&& sms_in[q+1]=='F'&& sms_in[q+2]=='F')
    {
     RC5_bit=0;
     UART1_Write(0X0D);
     UART1_Write(0X0A);
     flag=0;
     i=0;
    }
 
    }
   }
}

 
Last edited by a moderator:

problem in gsm receive & control LED ON & OFF

Hi here is my code.I am using sim900 & PIC16F876A. when message is received ON then led should be ON & when message is received OFF then led should be OFF


Code:
signed char sms_in[90];
bit flag;
char i=0;
void interrupt()
 {
  if (PIR1.RCIF==1)
  {
    if (UART1_Data_Ready())
   {
    sms_in[i] = UART1_Read();
    i++;
    if(i==88)
    {
   flag=1;
    }

   }

  }
}

void main()
{
     INTCON.GIE = 1;
     INTCON.PEIE = 1;
     PIE1.RCIE=1;

     TRISC5_bit = 0;
     UART1_Init(9600);
     Delay_ms(500);
     UART1_Write_Text("AT");
Delay_ms(1500);
UART1_Write_Text("AT+CMGF=1");
Delay_ms(1500);

while(1)
{
UART1_Write_Text("AT+CMGR=1");
Delay_ms(1500);

if(flag==1)
     {
    char q=75;
    if(sms_in[q]=='O'&& sms_in[q+1]=='N'&& sms_in[q+2]=='N')
    {
     RC5_bit=1;
     UART1_Write(0X0D);
     UART1_Write(0X0A);
     flag=0;
     // i=0;
    }

    else if(sms_in[q]=='O'&& sms_in[q+1]=='F'&& sms_in[q+2]=='F')
    {
     RC5_bit=0;
     UART1_Write(0X0D);
     UART1_Write(0X0A);
     flag=0;
     // i=0;
    }

    }
   }
}


Suppose I received message like "+CMGR: \"REC UNREAD\",\"+919325457889\",\"\",\"2014/12/27 17:04:02+22\"\r\nONN\r\nOK\r\n";

Then led should be ON

& when message received like "+CMGR: \"REC UNREAD\",\"+919325457889\",\"\",\"2014/12/27 17:04:02+22\"\r\nOFF\r\nOK\r\n";

Then led should be OFF
 
Last edited by a moderator:

Consider a simple point.

Your UART RX ISR will receive any response send from the modem, including an unkown number of command responses. How can you expect to find a CMGR message text at a specific buffer location? That's the basic problem with your code. There are additional problems like e.g. overflowing the buffer.

Instead you should design a clear scheme to decode modem responses.
- AT commands and responses are <CR><LF> terminated. Use this fact for a basic synchronization to new responses.
- decode response codes and specific fields by scanning for comma delimiters
 

But how to do this.I am confused
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top