0

I am using SIM900 GSM module connect to my AVR microcontroller.My compiler is Code Vision AVR. I want to send a message and I don’t want to use delay.I use an usart rx interrupt. I want to receive '>' in rx interrupt after sending number.Then send my meessage. But '>' charachter wasn’t received. I am checking this process with a 'a' variable. First of all 'a' variable is equal to zero and after 1 minute is equal to 2. But it is never equal to 3. As a result my message haven't been sent. I can't find my problem!

interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;
if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
  {
   rx_buffer[rx_wr_index++]=data;
     if(a==2)
        {
        if(data=='>')
            a=3;
        }
#if RX_BUFFER_SIZE == 256
 // special case for receiver buffer size=256
if (++rx_counter == 0)
  {
 #else
if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
   {
   rx_counter=0;
 #endif
   rx_buffer_overflow=1;
    }
   }
 }
void main()
{
//...rest of code
printf("at+cmgf=1%1c",enter);
printf("at+cmgda=%1c%s%1c%1c",q,del,q,enter);
while (1)
  {
//...rest of code
  RTC();

  if(minute!=1*count)
    flag1=0;
  if(minute==1*count && flag1!=1)
    {
    flag1=1;
    count++;
    a=1;
    }  


   if(a==1)
    {
    printf("at+cmgs=%1c%s%1c%1c",q,tel,q,enter);
    a=2;
    }

   if(a==3)
    {
    printf("Ba salam\rTemperature=%d\rHumidity=%d\rWind Direction=%s\rWind Speed=%d%1c%1c",temperature(),humidity(),direct1,anemometer(),cz,enter);
    a=0;
    }

  }

}

2 Answers2

0

You appear to be sending commands using lower case letters. The user manual specifies capital letters, that is, AT not at.

There is also something wrong with the minute-count code at the top of the loop. The flag1 will be set back to 0, which will eventually change a to 1 again, which will cause the message to be sent again. I don't think this is your immediate problem but it should be corrected.

We also don't know if the message is getting through to the SIM900. Maybe trying testing this by sending the AT commands over a terminal and checking the return values. (Your code doesn't check if the first two commands are acknowledged by the SIM900, for example.)

EDIT: Looking more closely, I see that your code is not following the protocol set out in the manual for sending a text. This may be because the manual has a typographical error. It has two sections labelled "Sending a Text", but one of them is actually for reading a text.

You don't need to include the AT+CMGDA=”DEL ALL” part. This is in the section for reading a text. Also, you have misspelled ”DEL ALL” as "DElALL".

The bigger problem is that sending the two commands so close together is clobbering the return codes.

UncleO
  • 8,299
  • 21
  • 29
  • According to [the user manual](http://www.rhydolabz.com/documents/gps_gsm/sim900_rs232_gsm_modem_opn.pdf) on p. 16, you should be getting responses from the device, but there aren't any in your console window. Did you try upper case letters, too? – UncleO Jul 22 '14 at 08:39
  • I always get response with "at". I was sending sms like this: I was writing printf(...)(like above code) and use delay_ms(8000). It worked.But now I use interrupt and I have problem. – AvrProgrammer Jul 22 '14 at 12:00
  • Both `AT` and `at` are ok. [V.250](http://www.itu.int/rec/T-REC-V.250-200307-I/en) explicitly states in chapter 5.2.1 Command line general format: `A command line is made up of three elements: the prefix, the body, and the termination character. The command line prefix consists of the characters "AT" or "at", or, to repeat the execution of the previous command line, the characters "A/" or "a/".` – hlovdal Jul 23 '14 at 00:16
  • @hlovdal Thanks for the link. Are you assuring us that the SIM900 conforms to this standard despite what it says in its user manual? It looks like the SIM900 is not responding according to the terminal output supplied by OP. – UncleO Jul 23 '14 at 03:00
  • V.250 (formerly V.25ter) is THE modem standard document covering basic AT command syntax and commands that absolutely all modems implemented the last two decades follow. While manufacturer AT command documents might not be explicit about it, [27.007](http://www.3gpp.org/ftp/Specs/html-info/27007.htm) (mobile phone AT command standard) is for instance very explicit in that it import the applicable basis from V.250. – hlovdal Jul 23 '14 at 10:50
0

You are not doing proper parsing of the responses from the modem.

First of all, never, ever, ever use time as a separator for command and response. You MUST read and parse everything received from the modem until you get a final response. Absolutely nothing else will work reliably. See this answer for some hints on how to fix.

And secondly, for AT+CMGS you MUST wait for a sequence of four characters, \r\n>, before sending data. There is also hints about this in the above linked answer.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • @AvrProgrammer It is not clear from the formatting of this answer, but the four characters returned are `\r`, `\n`, `>`, and a space character. Your code tried to send the string immediately after the `>` character, but it should wait for the space character first. – UncleO Jul 23 '14 at 03:05
  • Thanks for your helping.I must check space and > in If() in the interrupt ? – AvrProgrammer Jul 23 '14 at 19:20
  • Personally I would move any AT command handling out of the interrupt handler. Just let it build up a response buffer and then check and process the response buffer in your main loop. You will need to add some appropriate locking, but you will end up with a vastly better structure of your program. – hlovdal Jul 26 '14 at 05:50