Close or Esc Key

Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

ATmega GSM

5 posts / 0 new
Last post
F206
F206's picture
Offline
Last seen: 1 week 4 hours ago
Joined: 12/07/2017 - 23:57
ATmega GSM

Hello, I am trying to configure an atmega microcontroller to be able to send sms messages through the gsm, I was able to do it with an AT32U3C, but I am runing into trouble with this board.

my code goes as follows#include <asf.h>

#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <usart_megarf.h>
 
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (F_CPU/ (USART_BAUDRATE *16UL)) -1)
 
void usart_init();
void usart_transmit(char data);
void usart_transmit_string (char *str);
void send_sms(char *number, char *text);
 
 
int main (void)
{
board_init();
usart_init();
send_sms("3433339487\",129", "Quectel M10");
}
 
void usart_init()
{
UBRR1H = (unsigned char) (BAUD_PRESCALE >> 8); /
UBRR1L = (unsigned char)  BAUD_PRESCALE;
UCSR1B = (1<<RXEN1)  | (1<<TXEN1);
UCSR1C = (1<<UCSZ10) | (1<<UCSZ11);
}
 
void usart_transmit(char data)
{
while(!(UCSR1A & (1<<UDRE1)));
UDR1 = data;
}
 
void usart_transmit_string (char *str)
{
while(*str)
{
usart_transmit(*str++);
}
}
 
void send_sms(char *number, char *text)
{
 
usart_transmit_string("AT+IPR=57600");
usart_transmit_string("\r");
delay_ms(500);
 
usart_transmit_string("AT+CMGF=1"); // select text mode
usart_transmit_string("\r"); // ctrl-M
delay_ms(500);
 
usart_transmit_string("AT+CMGS=\"");            // start SMS command
usart_transmit_string(number);
usart_transmit_string("\r");
delay_ms(500);
 
usart_transmit_string(text);
usart_transmit_string("\r");
delay_ms(500);
 
usart_transmit_string("\x1a");     // ctrl-Z
 
}
 
anyone has any idea where I'm going wrong ?
Hari Prasaath K
Hari Prasaath K's picture
Offline
Last seen: 6 hours 50 sec ago
Joined: 20/01/2015 - 23:56
GSM

At which point you are facing a problem. like whether showing

1 . error in the program or

2. just message is not sending during operation

If the second one is the case try to add more delays while GSM AT commands

F206
F206's picture
Offline
Last seen: 1 week 4 hours ago
Joined: 12/07/2017 - 23:57
the error is that the message

the error is that the message is not being sent, i had the same delays inanotehr microcontroller (AT32UC3C), so i think my problem is with initializing the usart

Hari Prasaath K
Hari Prasaath K's picture
Offline
Last seen: 6 hours 50 sec ago
Joined: 20/01/2015 - 23:56
GSM

Check with the network in GSM, Before sending a message using coding, use GSM AT command any terminal software to test to verify whether GSM is working properly, also check with your hardware connections.

Check with below link it will help you, If u come again with the same problem, ask your querry

https://www.engineersgarage.com/contribution/how-to-interface-GSM-SIM-30...

Ashutosh Bhatt
Ashutosh Bhatt's picture
Offline
Last seen: 5 days 6 hours ago
Joined: 21/12/2010 - 15:59
first try to simulate your

first try to simulate your code using proteus

in proteus u can find virtual serial terminal in which you can find out if your message or string is sent to GSM module or not?