bad_wolf
bad_wolf

Reputation: 1

(GSM module SM5100B + ATMEGA16A interface) Trouble sending SMS using AT commands in C code

I am having trouble with my university project for embedded systems. The goal is to establish an interface between a SM5100B GSM module and ATMEGA16A microcontroller, using UART (which I did, using the correct ports from the datasheets), and to be able to send/receive simple SMS messages by sending AT commands trough the Tx and Rx ports from atmega to gsm and vice versa, via C code in Atmel.(not using hyperterminal)

When I tested the GSM module using TeraTerm, i was able to connect properly, and send AT commands easily, also managed to send and recieve an SMS with the SIM card inserted, so everything works fine.

Now I'm trying to do that using the microcontroller.

Here is the code I have so far:

#define F_CPU 7372800UL 
#include <stdio.h>
#include <stdlib.h>
#include <util/delay.h>
#include <avr/io.h>
#include <string.h>

#define BAUD 9600
#define MYUBRR ((F_CPU/16/BAUD)-1) //BAUD PRESCALAR (for Asynch. mode)

void GSM_init(unsigned int ubrr ) {
    /* Set baud rate */
    UBRRH = (unsigned char)(ubrr>>8);
    UBRRL = (unsigned char)ubrr;
    /* Enable receiver and transmitter */
    UCSRB = (1<<RXEN)|(1<<TXEN);
    /* Set frame format: 8data, 2stop bit */
    UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);    
}

void USART_Transmit(char data ) {
    /* Wait for empty transmit buffer */
    while ( !( UCSRA & (1<<UDRE)) );
    /* Put data into buffer, sends the data */
    UDR = data;
}

void USART_Transmits(char data[] ) {
    int i;

    for(i=0; i<strlen(data); i++) {
        USART_Transmit(data[i]);
        _delay_ms(300);
    }
}

int main(void)
{
    GSM_init(MYUBRR);

    char text_mode[] = "AT+CMGF=1";
    char send_sms[] = "AT+CMGS=";
    char phone_number[] = "00385*********";
    char sms[] = "gsm sadness";

    USART_Transmits(text_mode);
    _delay_ms(1000);
    USART_Transmits(send_sms);
    _delay_ms(1000);
    USART_Transmit(34);//quotation mark "
    //_delay_ms(300);
    USART_Transmits(phone_number);
    //_delay_ms(300);
    USART_Transmit(34);//quotation mark "
    //_delay_ms(300);
    USART_Transmit(13);//enter
    //_delay_ms(300);
    USART_Transmits(sms);
    _delay_ms(1000);
    USART_Transmit(26);//ctrl+z
    _delay_ms(300);
    USART_Transmit(13);//enter
    _delay_ms(3000);

    while (1) 
    {
    }
}

However, my code isn't working, it's not sending the message.

The functions for transmitting are taken from the datasheet and everywhere on the internet I search I find the same ones over and over again. Is the problem in AT responses that I'm not reading correctly? Or in parsing AT commands to the serial port? Can anybody help me understand where I'm going wrong with this, or where I can look for to understand how to make this work?

Upvotes: 0

Views: 309

Answers (0)

Related Questions