AT Commands
AT commands are an text-based control protocol primarily used for configuring and controlling cellular modems from host microcontrollers or manual typing. AT is an abbreviation of “ATtention”. AT commands are usually sent across a UART serial connection. Because they are text-based, it is also easy to control a modem connected to a terminal program (such as NinjaTerm) via serial.
The nRF91 series of SiPs (system-in-packages) from Nordic Semiconductor include modems which provide the AT command protocol for configuration and control.
Protocol
AT commands are text-based and limited to the ASCII character set. Each command and response is terminated with either a carriage return (CR
) and line feed (LF
) or just a carriage return. This is modem dependent and sometimes configurable. Although rare, some commands “bend” the rules and allow line termination inside the command. For example, the Nordic Semiconductor nRF91 modems allow the command AT%CMNG
to send a multiline certificate in .pem
format as part of the command. For example (this is sending the DigiCertGlobalRootG2
certificate):
AT%CMNG=0,16842753,0,"-----BEGIN CERTIFICATE-----MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBHMjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI2/Ou8jqJkTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx1x7e/dfgy5SDN67sH0NO3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQq2EGnI/yuum06ZIya7XzV+hdG82MHauVBJVJ8zUtluNJbd134/tJS7SsVQepj5WztCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyMUNGPHgm+F6HmIcr9g+UQvIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUTiJUIBiV5uNu5g/6+rkS7QYXjzkwDQYJKoZIhvcNAQELBQADggEBAGBnKJRvDkhj6zHd6mcY1Yl9PMWLSn/pvtsrF9+wX3N3KjITOYFnQoQj8kVnNeyIv/iPsGEMNKSuIEyExtv4NeF22d+mQrvHRAiGfzZ0JFrabA0UWTW98kndth/Jsw1HKj2ZL7tcu7XUIOGZX1NGFdtom/DzMNU+MeKNhJ7jitralj41E6Vf8PlwUHBHQRFXGU7Aj64GxJUTFy8bJZ918rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/iyK5S9kJRaTepLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTflMrY=-----END CERTIFICATE-----"
The simplest command is just simply AT
which the modem will respond to with OK
.
Proprietary commands are usually prefixed with the %
character, e.g. Nordic Semiconductor’s nRF91 SiP modems have a AT%CMNG
command to manage credentials (certificates and keys).
Commands
AT
This command is used to test if the modem is responding. It should respond with OK
. The command is just AT
followed by a carriage return and line feed.
AT+CGMR
This command is used to get the modem firmware version.
AT+CMGF
This command sets up the SMS mode of the modem.
AT+CMGW
This command is used to store a message in the memory of the SIM card.
Echo
Echoing is a common feature which is enabled when talking with devices using the AT command protocol. An important thing to note is the device will echo letters as they are typed into the terminal, not when you press enter. This may have implications when trying to use echo to match a sent command with a response.
AT Result Codes
It can be hard to determine the exact cause of an error because the modem usually just responds with ERROR
with no further information.
The following table lists the most commonly used AT result codes:
Result Code (Numerical) | Result Code (Textual) |
---|---|
0 | OK |
1 | CONNECT |
2 | RING |
3 | NO CARRIER |
4 | ERROR |
5 | CONNECT 1200 |
6 | NO DIALTONE |
7 | BUSY |
8 | NO ANSWER |