You are on page 1of 22

Interfacing GSM Modem

With Microcontroller

By: Gaurav Arora

Objective

Building a Embeded system with ability to Send


Sms using an GSM modem.

WORK FLOW

Initialize system to set parameters for


transmission and interrupt
System waits to be triggred using a sensor or
an manual External interrupt like Switch.
Detecting interrupt Atmega 16 Checks
availability of modem and tries to send SMS
using GSM Modem using AT Commands.

Defining Modules

System Consist of three modules:


> Interrupt Detection.
> Activating USART module Transmitting
and Receving Data.
> Sending AT commands to GSM Modem.

GSM MODEM

A GSM modem is a wireless modem that works


with a GSM wireless network.

AT commands are used to control modems.

Operations Performed by GSM Modem.

Reading, writing and deleting SMS messages.


Sending SMS messages.
Reading, writing and searching phone book entries.

GSM Modem Datasheet : 1122_datasheet.pdf in


your kit

Confiuring GSM Modem

Insert SIM card: Press the yellow pin to remove the


tray from the SIM cardholder. insert SIM card
Connect RS232 Cable: (Cable provided for RS232
communication) Default baud rate is 9600(using
2400)
with 8-N-1, no hardware handshaking.
o Pin 2 is RS232 level TX out
o Pin 3 is RS232 level RX in
o Pin 5 is Ground

Send AT commands.

Some Terms

BAUD RATE-A baud Rate is the measurement


of the number of times per second a signal in a
communications channel changes.
bps = baud per second x the number of bit per baud

8-N-1 this config means 8 databits,no parity


bit,1 stop bit.
RS232 - RS-232 (Recommended Standard
232) is a standard for serial binary single-ended
data and control signals connecting . It is
commonly used in computer serial ports.

AT commands

AT is the abbreviation of ATtention.


AT commands are instructions used to control a
modem.
AT commands used to send SMS
AT ; -To check if the device is available
AT+CMGF=1; - select the operating mode GSM or mobile using 0 and
1(GSM)
AT+CMGS=mobile no.<CR>Text Message<Ctrl+Z>; -AT
commands +CMGS can be used to send SMS messages

All AT commands are available in 1122_at_AT_Commands.pdf in your kit

Interfacing Modem with


Microcontroller

Output of hyper-terminal for AT


commands to modem

USART

USART - Universal synchronous and asynchronous receiver


and transmitter.
Main Registers UCSRA,UCSRB,UCSRC,UBRR,UDR
UCSRx USART Control and Status Register A,B,C.
UBRR USART Baud rate Register
UDR USART Data Register.

Two UDR USART register to transmit and receive to provide


full duplex mode.
Must Read Status Bits before receiving or transmitting Data
(most important)
TXC and RXC flags.

Initializing
USART module

Activating USART module(1)

we have to enable the UART Receiver and


Transmitter using bit RXEN and TXEN in
UCSRB register

Activating USART module(2)

Bit 3 TXEN: Transmitter Enable

Writing this bit to one enables the USART Transmitter. The


Transmitter will override nor-mal port operation for the TxD
pin when enabled. The disabling of the Transmitter

In UCSRC register UPM1:0: bit are used to set parity bits


to 0,Bit 3 USBS:to select Stop bits, Bit 2:1 UCSZ1:0: to
select character size to 8 bits.

Activating USART module(3)

Setting Baud Rate:


Set values of UBRR -USART Baud rate register
according to table:

USART initialization code


UBRRH=0x00;
UBRRL = (unsigned char)BaudRate; /* Set the
baud rate */
UCSRB = 0b00011000; // enable transmitter and
reciever
UCSRC = 0b10000110; // 8 bit data, no parity bit,
1 stop bit.

USART Transmission

In UCSRA register Bit 5 UDRE: USART Data


Register Empty

The UDRE flag indicates if the transmit buffer (UDR) is


ready to receive new data. If
UDRE is one, the buffer is empty, and therefore ready to
be written.
If UDRE is one put data in the buffer.

Problem with Baud rates

GSM modem supports a wide range of baud


rates 1120-12000
We cannot send data using higher baud rate
while transmitting USART as higher baud rate
require higher clock speed which is not
available on board
4800 and 9600 baud rates are not supported
with 1MHz oscillator.

USART RECEPTION

In UCSRA register bit 7: Bit 7 RXC: USART Receive


Complete

This flag bit is set when there are unread data in the
receive buffer and cleared when thereceive buffer is
empty (i.e., does not contain any unread data).

Interrupt Detection

Code sniplets used to set Interrupt.

GICR = 0x40; // enable external interrupt 0


MCUCR = 0x02; // activate external interrupt0 (on pin16)
it recognizes rising edge
sei();//set enable interrupts.

If externel interrupts is provided to system then control


goes to interrupt handler and set a flag variable to one.

And send the required Sms.

Have a look on code!!


Any Questions??

Thank You!

You might also like