Embedded Freaks..

August 19, 2008

Handling URC (Unsolicited Result Code) in Hayes AT Command

Filed under: programming-tips — Tags: — kunilkuda @ 11:19 am

URC is the message that is sent from the ME (Mobile Equipment, eg. GSM/GPRS/CDMA modem) that’s not the result of the AT command.

Here’s some examples: RING is sent when the modem is called, CONNECTED is sent when the modem answer the call, or +CNMI is sent when modem received new SMS. You can think of URC as modem’s soft interrupt.

So, what’s the problem with the URC ? Unless you haven’t programmed any of application that deals with the modem directly, you will notice that URC sometimes destroy your parser state machine when it fires in middle of executing AT command.

Here’s the illustration of the URC problem:

application>AT+CMGL=4 # List all of SMS inside the ME
ME> RING # Incoming call
ME> OK # There's no SMS inside the ME
ME> RING # Incoming call

The RING between AT+CMGL and OK is happenned because the AT command hasn’t reach the serial port, while the incoming call is received. This may break the AT command parser. But there’s a way to help it.