# How to wait for '>' in SIM900 message format

Hello all I am trying to send sms using SIM900 and PIC18F2520. I have button attached to pin of MCU. So whenever the button is pressed, sms should be sent.Following is the code I am using to send SMS:

if(PORTCbits.RC1==1)
{
DelayMs(10);
if(PORTCbits.RC1==1)
{
UARTsend("AT+CMGS=\"99********\"\r ");
DelayMs(100);
UARTsend("Hello World");
DelayMs(10);
UARTsend("\x1A ");
DelayMs(10);
}
}


Now when I run it in debug mode, I receive sms. But when I program the device, what happens is it send AT+CMGS command and then send Hello world and \x1A. After sending all these things, then it shows >, that means now it wait for the message content. I dont know why it is happening. I have given the proper delay after AT+CMGS. I tried increasing the delay but again no changes. How to wait for > while sending sms. Please help

• Easiest way is to write a function which returns the latest character received on UART. And then block with a while loop: while(GSM_uart_recieve() != '>'); . Of course it can be improved with a timer to make a simple timeout functionality to ensure you won't stuck in the while loop if the module does not answer. – Bence Kaulics Jul 26 '16 at 8:40
• You can handle it with and ISR as well, if you want a non-blocking solution. So you can check all received byte in the UART receive complete interrupt and set a flag if > is received and so on. – Bence Kaulics Jul 26 '16 at 8:43
• Yes I have tried receiving it using if(ReadUSART()=='>') and then send sms. but it never enters in the if condition. I have read somewhere that sim900 also sends some <CR><LF> maybe because of these its not entering in if condition. How to process them – S Andrew Jul 26 '16 at 8:49
• What is the return value of ReadUSART()? – Bence Kaulics Jul 26 '16 at 8:54
• ReadUSART() return a byte from UART. I have partially solved the problem by increasing the delay to 5sec after sending AT+CMGS so now its working but I think thats not the proper solution to it. It should check if it reads > and then send the message. I am trying it. – S Andrew Jul 26 '16 at 8:56