March 20th, 2013, 11:11 PM
-
USART receive from GSM error
Hi, I'm using a TC35 GSM board to send and receive sms. I'm able to send SMS without any problem. I'm having trouble reading it off the SIM card.
I tested this code using hyperterminal and I'm able to receive data from the keyboard and display on my LCD. But when I connect it to the GSM modem, it doesnt receive any data.
Code:
#include <p18F4520.h>
#include <delays.h>
#include <stdio.h>
#include <usart.h>
#include <system4520.h>
void usart_init(void);
unsigned char uart_rec(void);
void main(void)
{
unsigned char data[14];
int i;
usart_init();
lcd_init();
clear_screen();
cursor_set(0,0);
putrsUSART("AT\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGF=1\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGR=1\r\n");
for(i = 0; i < 14; i++)
{
data[i] = uart_rec();
}
Delay10KTCYx(50);
for(i = 0; i < 14; i++)
{
WriteC(data[i]);
}
Delay10KTCYx(50);
}
void usart_init(void)
{
OpenUSART(USART_TX_INT_OFF & //Transmit interrupt off
USART_RX_INT_ON & //Receive interrupt on
USART_ASYNCH_MODE & //Asynchronous mode
USART_EIGHT_BIT & //8-bit data
USART_CONT_RX & //Continuous reception
USART_BRGH_HIGH,25);//9600 baud3
}
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(PIR1bits.RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the data received
#include <p18F4520.h>
#include <delays.h>
#include <stdio.h>
#include <usart.h>
#include <system4520.h>
void usart_init(void);
unsigned char uart_rec(void);
void main(void)
{
unsigned char data[14];
int i;
usart_init();
lcd_init();
clear_screen();
cursor_set(0,0);
putrsUSART("AT\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGF=1\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGR=1\r\n");
for(i = 0; i < 14; i++)
{
data[i] = uart_rec();
}
Delay10KTCYx(50);
for(i = 0; i < 14; i++)
{
WriteC(data[i]);
}
Delay10KTCYx(50);
}
void usart_init(void)
{
OpenUSART(USART_TX_INT_OFF & //Transmit interrupt off
USART_RX_INT_ON & //Receive interrupt on
USART_ASYNCH_MODE & //Asynchronous mode
USART_EIGHT_BIT & //8-bit data
USART_CONT_RX & //Continuous reception
USART_BRGH_HIGH,25);//9600 baud3
}
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(PIR1bits.RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the data received
#include <p18F4520.h>
#include <delays.h>
#include <stdio.h>
#include <usart.h>
#include <system4520.h>
void usart_init(void);
unsigned char uart_rec(void);
void main(void)
{
unsigned char data[14];
int i;
usart_init();
lcd_init();
clear_screen();
cursor_set(0,0);
putrsUSART("AT\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGF=1\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGR=1\r\n");
for(i = 0; i < 14; i++)
{
data[i] = uart_rec();
}
Delay10KTCYx(50);
for(i = 0; i < 14; i++)
{
WriteC(data[i]);
}
Delay10KTCYx(50);
}
void usart_init(void)
{
OpenUSART(USART_TX_INT_OFF & //Transmit interrupt off
USART_RX_INT_ON & //Receive interrupt on
USART_ASYNCH_MODE & //Asynchronous mode
USART_EIGHT_BIT & //8-bit data
USART_CONT_RX & //Continuous reception
USART_BRGH_HIGH,25);//9600 baud3
}
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(PIR1bits.RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the data received
#include <p18F4520.h>
#include <delays.h>
#include <stdio.h>
#include <usart.h>
#include <system4520.h>
void usart_init(void);
unsigned char uart_rec(void);
void main(void)
{
unsigned char data[14];
int i;
usart_init();
lcd_init();
clear_screen();
cursor_set(0,0);
putrsUSART("AT\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGF=1\r\n");
Delay10KTCYx(50);
putrsUSART("AT+CMGR=1\r\n");
for(i = 0; i < 14; i++)
{
data[i] = uart_rec();
}
Delay10KTCYx(50);
for(i = 0; i < 14; i++)
{
WriteC(data[i]);
}
Delay10KTCYx(50);
}
void usart_init(void)
{
OpenUSART(USART_TX_INT_OFF & //Transmit interrupt off
USART_RX_INT_ON & //Receive interrupt on
USART_ASYNCH_MODE & //Asynchronous mode
USART_EIGHT_BIT & //8-bit data
USART_CONT_RX & //Continuous reception
USART_BRGH_HIGH,25);//9600 baud3
}
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(PIR1bits.RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the data received
}