In the previous tutorial, we covered how to interface a SIM900A GSM-GPRS modem with Raspberry Pi, Arduino, and desktop computers. SIM900A can communicate data with the controlling device over the universal asynchronous receiver/transmitter (UART), I2C, or SPI protocol.
The modem is a piece of mobile equipment with an IMEI number that’s capable of all cellular operations (voice calls, SMS, MMS, faxes, and the Internet). It “understands” AT commands, and can be configured and operated by passing these commands to it.
There was a time when mobile phones (such as Nokia handsets) were built by directly interfacing a display screen, keypad, speakers, microphone, and battery system to such modems. Now, smartphones are built using high-end processors that run complex mobile operating systems (iOS, Android, Windows).
A mobile-platform processor is interfaced with the following to build a full-fledged portable computer that’s a smartphone.:
- A touchscreen
- A dedicated graphic processing unit (GPU)
- Microphone and speakers
- Camera and sensors
- A neural processing unit (NPU) for artificial intelligence
- A battery system and a wireless modem, such as a 4G/5G modem. (Even in smartphones, there is the wireless modem that renders complete cellular solution.)
Wireless modems talk over the AT commands, which are an abbreviation for “attention.” These commands serve as instructions that control the wireless modem. Wireless modules, like SIM900A, are essentially mobile equipment with console access.
The console communicates and responds to the AT commands, which may be exchanged with a modem using the serial (UART), I2C, or SPI interface. The controlling device can be any microcontroller or computer. Much like in the previous tutorial — where we discussed how to interface SIM900A with Raspberry Pi, Arduino, or other microcontrollers, including desktop computers using USB-serial boards — the modem can also be controlled by all these devices.
Understanding the AT commands
The AT commands are instructions for a wireless modem. The basic AT commands are a subset of the Hayes command. There are also AT commands that are implemented in compliance with the cellular solution (such as GSM-GPRS, GSM-GPRS+GNSS, WCDMA/HSPA/HSPA+, 4G/LTE, and CAT/NB-IoT).
The modem manufacturer may also implement a subset of the AT commands on a particular modem. For example, the way, basic, and extended AT commands that are implemented on a modem may differ from one vendor to another.
Each modem has and responds to its own instruction set. The AT commands are the same for a wireless or phone modem. Similar to a processor that receives instructions and outputs results over parallel ports (or, in some cases, over serial ports), a modem receives commands and responds to them over standard serial interfaces (such as the UART, SPI, and I2C).
The SIM900A modem supports the AT commands in compliance with:
- The ITU-T (the International Telecommunication Union, Telecommunication sector)
- The V.25TER document
- The ETSI GSM07.07 (i.e. the ETSI standard AT command is set for GSM mobile equipment)
- The ETSI GSM07.05 (i.e. the ETSI standard is for short message service or SMS)
- Cell broadcast service (or CBS)
It also implements the AT commands for the SIM application toolkit, GPRS support, TCP/IP application toolkit, and the IP, HTTP, and FTP applications — and has additional AT commands implemented by its vender SIMCOM.
However, the modem may not support all of the AT commands under the ITU-T and ETSI specifications and only a subset of them. The supported AT commands can be used to configure a modem and access services, such as voice calls, SMS, MMS, faxes, and data link over the TCP/IP, IP, HTTP, and FTP protocols.
The types of AT commands
The basic AT commands are a subset of the Hayes Commands. The others are called extended AT commands.
There are four types of basic AT commands:
1. Test commands: used to test the compatibility of a command with a modem and to confirm if a command has been implemented or is supported by the modem. The modem may respond with an OK or a supported configuration of the command in response to the test command. These commands are in a format AT+<x>=? where <x> is the command.
2. Read commands: used to know the mobile phone or modem settings. These commands are in a format AT+<x>? where <x> is the command.
3. Set commands: used to modify the mobile phone or modem settings. These commands include parameters that must be set to change a particular phone/modem setting. They’re in the format AT+<x>=<n> where <x> is the command and <n> are the optional arguments. If the arguments are not passed in the command, the modem assumes the default mode.
4. Execution commands: used for executing a cellular operation, such as to make or answer a voice call, read, send, or delete an SMS, etc. These commands are in a format AT+<x> where <x> is the command.
The AT commands’ syntax
All of the AT commands begin with the prefix “AT” or “at,” and ends with a command-line enter <CR>. This is why these commands are called AT commands.
The modem response comes in the format of <CR><LF><Response><CR><LF>.
The AT commands of the SIM900A can be divided into three subsets:
1. Basic syntax: are in the format “AT<x><n>” where <x> is the command and <n> is the optional arguments. If the arguments are not passed, the default arguments are automatically used by the modem.
2. S parameter syntax: are in a format “ATS<n>=<m>” where <n> is index of S register to set and <m> is value to assign to it. The <m> is optional and if value is not passed, default values are assumed by modem.
3. Extended syntax: are syntax for extended AT commands. The syntax for test, read, set, and execution commands are mentioned above.
Therefore, the basic commands use a basic or an S parameter syntax and the extended AT commands use a different syntax, according to their type.
The command-line buffer of the SIM900 modem can accept a maximum of 556 characters. It’s possible to pass a single or multiple commands in a line. If the line exceeds 556 characters, however, none of the commands will execute and the modem will return “ERROR.”
If a single command is passed in a line, another command cannot be passed until the response from modem is received. If multiple commands are passed in a line, the “AT” or “at” must be prefixed at the beginning of the line.
The basic and s-parameter syntax commands shouldn’t be delimited but all extended AT commands must be delimited by a semicolon (;) on the line. The line must also end with the command-line enter <CR> to pass all of the commands to the modem.
The SIM900 AT commands default to the IRA character set. The other character-sets supported by the SIM900 modem includes:
- GSM format
The character set affects the SMS, SMS cell broadcast messages, phonebook entries, and the SIM application toolkit alpha strings. The character set in use by the modem can be interrogated using the AT command “AT+CSCS.”
The AT commands list
The SIM900 modem supports the following basic AT commands:
This list is relatively short and only presents a few of the more common commands. The SIM900 modem supports hundreds of AT commands as per different specifications.
The AT commands for voice calls
These AT commands are useful to make and receive voice calls using a SIM900 modem:
The AT commands for data link over an HTTP protocol
On an HTTP protocol, data can be communicated using two methods:
1. GET method – used to get data from the server
2. POST method – used to post data to the server
But first, the modem must connect to a GPRS by configuring a bearer profile.
These AT commands can help:
These AT commands are useful in getting data from the server using the HTTP GET method:
These AT commands are useful in getting data from the server using the HTTP GET method:
The AT commands for a data link over the TCP/IP protocol
The SIM900 modem also supports a data link over the TCP/IP protocol. The modem can connect over the TCP/IP protocol in two modes:
1. Single-connection mode – only one connection can be established
2. Multi-connection mode – a maximum of eight connections can be established
The TCP/IP application can also have two modes: transparent and non-transparent. In multi-connection mode, the SIM900A works only in a non-transparent application mode.
These AT commands are useful for communication as TCP client by the modem to a server:
How to send AT commands from a user-program
The AT commands can be sent to a wireless modem via a user program, such as Python script and as bytes. A programming language may use an escape sequence for the command-line enter.
For example, in Python3, the command-line enter can be passed serially using a carriage return, for which ‘\r’ is the escape sequence. In Python2, for the command-line enter, the ‘\r\n’ is the escape sequence.
In a user-program, the string manipulation functions can be used to properly encode and decode the AT commands and their responses. String manipulation functions are particularly useful when characters, such as CTRL+Z (substitute), must be passed along the AT command.
For example, in Python3, the str.encode() function can be used to encode the AT commands in a script (user-program). CTRL+Z can be passed using the char() function with 26 as the argument — such as char(26) or char(0x1A).
In the next tutorial, we’ll learn how to make and receive calls, and how to send and receive SMS on Raspberry Pi and a desktop computer by using the SIM900A modem.