Microcontroller › AVR › Cannot receive sms from gsm mobile
- This topic has 1 reply, 2 voices, and was last updated 6 years, 5 months ago by Hari Prasaath K.
-
AuthorPosts
-
March 18, 2016 at 1:08 pm #4378BakhtiarParticipant
Dear Concern,
I am facing problem to receive sms . Below is my code . Please help me .
in main block:
int main (void)
{
uint8_t x = 0;board_init();
cpu_irq_enable();
DDRB = 0x7f;
lcd_initialise();
usart_setup();
initialize_mdm();
while (1)
{
msg = strstr(rx_data,"RING");
if (!(strncmp(msg,"RING",4)))
{
msg = strstr(rx_data,"1714094407");
if (!(strncmp(msg,"1714094407",10)))
{
lcd_command(0x01);lcd_display("Calling:");lcd_command(0xc0);
while (x<10){lcd_data(*(msg+x));x++;}x=0;delay_s(1);
tx_data("ATH");serial_enter();delay_s(1);
lcd_command(0x01);lcd_display("Call Rejected");
}
clear_rx_data();
}
msg = strstr(rx_data,"CMTI");
if (!(strncmp(msg,"CMTI",4)))
{
lcd_command(0x01);lcd_display("SMS Received");
tx_data("AT+CMGR=");tx_char(*(msg+11));serial_enter();delay_s(1);
clear_rx_data();
}
}
}in uart setup:
#define RXD PD0
#define TXD PD1uint16_t rx_count=0;
char rx_data[255];void usart_setup(void);
void tx_data(char *data_string);
void tx_char(char);
void clear_rx_data(void);
void serial_enter(void);void usart_setup()
{
// Making TXD as output pin
DDRD |= 1<<TXD;
// Making RXD as input pin
DDRD &= ~(1<<RXD);
// Baud Rate is 9600 selected with 0.2% error
UBRRL = 0x0c;
// Asynchronous operation, Parity mode disabled, 1-stop-bit and 8-bit character size
UCSRC |= 1<<URSEL;
UCSRC |= 1<<UCSZ1|1<<UCSZ0;
// Enabling Double Transmission rate
UCSRA |= 1<<U2X;
// Enabling Receive complete interrupt, transmitter and receiver
UCSRB |= 1<<RXCIE|1<<TXEN|1<<RXEN;
}void tx_data(char *data_string)
{
uint16_t i=0;
while (data_string!=0)
{
// Wait until UDRE goes high
while (!(UCSRA & 0x20));
// Place the data byte
UDR = data_string;
// Wait until TXC flag goes high
while (!(UCSRA & 0x40));
// Clear TXC flag by writing '1' to its bit position
UCSRA |= 0x40;
i++;
}
}void tx_char(char data_byte)
{
// Wait until UDRE goes high
while (!(UCSRA & 0x20));
// Place the data byte
UDR = data_byte;
// Wait until TXC flag goes high
while (!(UCSRA & 0x40));
// Clear TXC flag by writing '1' to its bit position
UCSRA |= 0x40;
}void clear_rx_data()
{
uint16_t clear=0;
while (clear<rx_count)
{
rx_data[clear] = 0;
clear++;
}
rx_count=0;
}void serial_enter()
{
tx_char(0x0d); // Carriage return<CR>
delay_ms(50);
tx_char(0x0a); // Line feed<LF>
delay_ms(50);
}ISR(USART_RXC_vect)
{
// Store the received byte in variable
rx_data[rx_count] = UDR;
rx_count++;
}should i miss any steps.
July 23, 2018 at 6:51 am #14872Hari Prasaath KParticipantCheck with the below link for brief description of code
ablab.in/receiving-an-incoming-call-in-sim800-gsm-gprs-modem-with-avr-atmega32-microcontroller/
-
AuthorPosts
- You must be logged in to reply to this topic.