LPC2148 – GSM Interfacing

This article is a continuation of the series of tutorials on the LPC2148 Microcontroller (ARM7). The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the Keypad with LPC2148 (ARM7). Now, we will see GSM Interfacing with LPC2148.

Suggestion to read

Components Required

  • GSM SIM900A module
  • LPC2148 Development Board

GSM Interfacing with LPC2148

Connection

Micro controller’s RX (P0.1) is connected to the GSM module’s TX and Micro controller’s TX(P0.0) is Connected to the GSM module’s RX pin.

Code

SMS Sending Code

This code is used to send the message to a particular number.

#include <lpc214x.h>

#define NUMBER "9876543210"          //Here insert your number where you want to send message

void ser_init(void);
void tx(unsigned char c);
unsigned char rx(void);
void tx_str(unsigned char *s);

void sms(unsigned char *num1,unsigned char *msg);
void gsm_delay(void);

unsigned int dell;

int main()
{
        ser_init();
        sms(NUMBER, "Welcome to the Embetronicx");
        while(1);
}

void sms(unsigned char *num1,unsigned char *msg)
{
    tx_str("AT");
    tx(0x0d);
    gsm_delay();

    tx_str("AT+CMGF=1");
    tx(0x0d);
    gsm_delay();

    tx_str("AT+CMGS=");
    tx('"');
    while(*num1)
        tx(*num1++);
    tx('"');
    tx(0x0d);
    gsm_delay();

    while(*msg)
        tx(*msg++);
    tx(0x1a);
    gsm_delay();
}

void gsm_delay()
{
    unsigned long int gsm_del,ff;
    for(gsm_del=0;gsm_del<=500000;gsm_del++)
         for(ff=0;ff<25;ff++);
}

void ser_init()
{
    VPBDIV=0x02;      //PCLK = 30MHz
    PINSEL0=0x5;
    U0LCR=0x83;
    U0DLL=195;
    U0DLM=0;
    U0LCR=0x03;
    U0TER=(1<<7);
}

void tx(unsigned char c)
{
    U0THR=c;
    while((U0LSR&(1<<5))==0);
}

void tx_str(unsigned char *s)
{
    while(*s) {
        tx(*s++);
    }
}

unsigned char rx()
{
    while((U0LSR&(1<<0))==0);
    return U0RBR;
}

Calling Code

This code is used to Call a particular number.

#include <lpc214x.h>

#define NUMBER "9876543210"          //Here insert your number where you want to send message

void ser_init(void);
void tx(unsigned char c);
unsigned char rx(void);
void tx_str(unsigned char *s);

void call(unsigned char *num2);
void gsm_delay(void);

unsigned int dell;

int main()
{
        ser_init();
        call(NUMBER);
        while(1);
}

void call(unsigned char *num2)
{
    tx_str("AT");
    tx(0x0d);
    gsm_delay();

    tx_str("AT+CMGF=1");
    tx(0x0d);
    gsm_delay();

    tx_str("ATD");
    while(*num2)
        tx(*num2++);
    tx(';');
    tx(0x0d);
    for(dell=0;dell<=30;dell++)
        gsm_delay();

    tx_str("ATH");
    tx(0x0d);
    gsm_delay();
}

void gsm_delay()
{
    unsigned long int gsm_del,ff;
    for(gsm_del=0;gsm_del<=500000;gsm_del++)
         for(ff=0;ff<25;ff++);
}

void ser_init()
{
    VPBDIV=0x02;      //PCLK = 30MHz
    PINSEL0=0x5;
    U0LCR=0x83;
    U0DLL=195;
    U0DLM=0;
    U0LCR=0x03;
    U0TER=(1<<7);
}

void tx(unsigned char c)
{
    U0THR=c;
    while((U0LSR&(1<<5))==0);
}

void tx_str(unsigned char *s)
{
    while(*s) {
        tx(*s++);
    }
}

unsigned char rx()
{
    while((U0LSR&(1<<0))==0);
    return U0RBR;
}

That’s guys… You can use this code to send a message and call to a particular number.

In our next tutorial, we will see how to interface the RFID reader with LPC2148 (ARM7). If you want to use FreeRTOS on LPC2148, then please refer FreeRTOS series.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
STM32F7 Bootloader TutorialsRaspberry PI Pico Tutorials
STM32F103 Bootloader TutorialsRT-Thread RTOS Tutorials
Zephyr RTOS Tutorials - STM32Zephyr RTOS Tutorials - ESP32
AUTOSAR TutorialsUDS Protocol Tutorials
Product ReviewsSTM32 MikroC Bootloader Tutorial
VHDL Tutorials

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Table of Contents