---
title: "Registering a SIM Card to a Cellular Network with AT Commands"
date: 2026-01-02
author: Lawrence
tags: [modem, cellular, iot, embedded, at-commands, sim7080g, cat-m, nb-iot, lte-m]
image:
path: "/images/blog/rp2040-modem.jpg"
alt: rp2040-modem-setup
---
# Registering a SIM Card to a Cellular Network with AT Commands
This guide walks through registering a SIM card to a cellular network using AT commands with Cat-M and NB-IoT modems. When high-level frameworks fail, understanding these steps helps you diagnose what went wrong.
## Why Work with AT Commands Directly?
Frameworks handle registration automatically until they don't. While PPP (Point-to-Point Protocol) can establish network interfaces, AT commands provide visibility into each step: SIM initialization, signal strength, APN configuration. This transparency is essential for debugging.
## The Hayes AT Command Protocol
AT commands are a text-based protocol standard since 1981. Commands follow the pattern `AT+COMMAND[=parameters]`, returning either `OK` or `ERROR` with optional response data. Most modems support standardized 3GPP commands plus vendor-specific extensions.
## Step 1: Power On and Modem Initialization
Most modems require a power enable pin pulse (1-2 seconds, check datasheet). The SIM7080G needs 1.5 seconds.
Boot time is often understated in datasheets. The SIM7080G needs 35+ seconds (not the documented 30) before accepting AT commands. Test with repeated `AT` commands every 4 seconds until you get `OK`.
Enable echo for debugging: `ATE1`
## Step 2: SIM Card Detection
Check SIM status with `AT+CPIN?`:
- `+CPIN: READY` - SIM ready
- `+CPIN: SIM PIN` - PIN required
- `+CME ERROR: 10` - SIM not inserted
Consumer prepaid SIMs work fine for development if they have an active data plan and the network supports Cat-M/NB-IoT in your region.
Enable verbose errors: `AT+CMEE=2` (converts generic `ERROR` to specific codes like `+CME ERROR: 30`)
## Step 3: Network Mode Configuration
**For SIM7080G (Cat-M/NB-IoT):**
- Set LTE-only: `AT+CNMP=38`
- Select mode: `AT+CMNB=1` (Cat-M), `AT+CMNB=2` (NB-IoT), `AT+CMNB=3` (both - recommended)
Cat-M offers higher bandwidth (~375 kbps) and mobility. NB-IoT offers lower power and better indoor coverage (~60 kbps). Use `AT+CMNB=3` for automatic selection during development.
**For GSM/GPRS/3G modems:** Use `AT+CNMP` or `AT+CMODE` (vendor-specific - consult your manual).
## Step 4: Access Point Name (APN) Configuration
Now configure the APN: `AT+CGDCONT=1,"IP","<apn>"`
Find your carrier's APN on their website (e.g., Safaricom uses "safaricom", Airtel uses "internet").
**Common mistake:** Mismatched APN types (IoT vs consumer) cause registration to succeed but data to fail.
## Step 5: Network Registration
Start automatic registration: `AT+COPS=0`
Monitor status with `AT+CREG?`:
- `0` - Not searching
- `1` - Registered (home)
- `2` - Searching
- `3` - Denied
- `5` - Registered (roaming)
Registration takes 30-120 seconds even with good signal.
Check signal with `AT+CSQ`:
- `0-9`: Poor (may fail)
- `10-14`: Adequate
- `15-31`: Good to excellent
- `99`: No signal
Verify operator: `AT+COPS?` (returns network name and mode)
## Step 6: Data Context Activation
Check if PDP context is active: `AT+CGACT?`
Response `+CGACT: 1,1` means context 1 is active. If it shows `0` despite successful registration, your APN is likely wrong.
## Common Registration Failures
**SIM Not Detected** (`+CME ERROR: 10`): Check physical insertion, try SIM in a phone.
**No Signal** (`+CSQ: 99,99`): Check antenna connection, move outdoors.
**Stuck Searching** (`+CREG: 0,2`): Weak signal, wrong network mode, or unsupported technology. Try `AT+CMNB=3`.
**Registration Denied** (`+CREG: 0,3`): SIM inactive, expired plan, or carrier incompatibility.
**Registered But No Data** (`+CREG: 0,1` but `+CGACT: 1,0`): Wrong APN or no data plan.
## Practical Implementation Example
Find complete implementation here: https://github.com/learnqtkenya/pico-modem
## Key Takeaways
- **Boot timing:** Datasheets understate requirements. Add margin (35s vs 30s for SIM7080G).
- **Consumer SIMs work** with proper APN and active data plans.
- **Wrong APN** causes registration success but data failure.
- **Registration takes 30-120 seconds** even with good signal.
- **RSSI < 10** causes issues; < 5 usually prevents registration.
- **Enable `AT+CMEE=2`** for specific error codes instead of generic failures.
AT commands reveal what frameworks hide. When debugging fails, this visibility transforms guesswork into systematic diagnosis.
## References and Further Reading
### Official Documentation
- [SIM7070/SIM7080/SIM7090 Series AT Command Manual V1.04](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/unit/sim7080g/en/SIM7070_SIM7080_SIM7090%20Series_AT%20Command%20Manual_V1.04.pdf) - Complete AT command reference
- [SIM7080G Hardware Design Manual](https://www.texim-europe.com/Cmsfile/SMM-SIM7080G-Hardware-Design-V1.04-DS-200525-TE.pdf) - Power sequence and electrical specifications
### AT Command References
- [AT+CMNB – Preferred Selection between CAT-M and NB-IoT](https://m2msupport.net/m2msupport/atcmnb-preferred-selection-between-cat-m-and-nb-iot/) - Network mode configuration
- [AT+CSQ – Signal Quality](https://m2msupport.net/m2msupport/atcsq-signal-quality/) - RSSI interpretation and signal strength