marthoma
Junior Member level 3
- Joined
- Oct 15, 2014
- Messages
- 25
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 171
char get_char()
{
while(!(U0LSR & 0x01));//Wait until UART0 gets sum char
return U0RBR;
}
First AT<CR> must be send with inter-character delay for the autobaud feature to work, presumed you are sending at a different baud rate than initially assumed by the modem.
int main()
{
lcd_init();
USARTInit();
while(1)
{
send_char('A');
send_char('T');
send_char(0x0d); //carriage return
soft_delay_ms(50);
if(!CheckGSM_Response())
{
continue;
}
}
}
//code to send_char()
//code to receive
unsigned char buff[16];
unsigned char receive_char()
{
int i=0;
while(!(U0LSR&0x01));
return U0RBR;
}
int CheckGSM_Response()
{
int i=0;
int len=0;
char data=0;
//soft_delay_ms(10);
while(data!='\r')
{
len++;
data=receive_char();
buff[i++]=data;
}
buff[i-1] = '\0';
if(buff[0]!=0x0D | buff[1]!=0x0A)
{
return 0;
}
if(buff[len]!=0x0D | buff[len-1]!=0x0A)
{
return 0;
}
if((buff[2]!='O'||buff[2]!='o')&&(buff[3]!='K'||buff[3]!='k'))
{
return 0;
}
gotoloc(2,1);
LCD_WriteString("received OK");
return (1);
}
//code for uartinit()
while(data!='\r')
{
len++;
data=receive_char();
buff[i++]=data;
}
while(!(U0LSR&0x01));
return U0RBR;
And another delay before <CR> character. As suggested in post #2.should i send "at" as 'a' 't' with some delay in between??
#include<lpc214x.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include "lcd.h"
void send_string(char *p);//Sends a string of data through UART1
void send_char(char data);
void USARTInit(void);
unsigned char receive_char(void);
int main()
{
char ch[16]="";
int i=0;
lcd_init();
USARTInit();
gotoloc(1,1);
LCD_WriteString("welcome to gsm");
soft_delay_ms(1000);
while(1)
{
LCD_Cmd(0x01);
soft_delay_ms(100);
//sending AT command
LCD_WriteString("sending AT");
U0FCR=0x04;
send_char('A');
soft_delay_ms(10);
send_char('T');
//soft_delay_ms(10);
send_char(0x0d); //carriage return
while(ch[i]!='\r')
{
ch[i]=receive_char();
LCD_Write_DATA(ch[i++]);
}
//send_char(0x0a);//line feed
}
}
void send_char(char data)
{
while(!(U0LSR&0x20));
U0THR=data;
}
void send_string(char *p) //Sends a string of data through UART1
{
while(1)
{
if(*p=='\0')
break;
send_char(*p++);
}
}
unsigned char receive_char()
{
while(!(U0LSR&0x01));
gotoloc(2,1);
LCD_WriteString(" 2 ");
return U0RBR;
}
void USARTInit()
{
PINSEL0 = 0x00000005; //Select TxD for P0.0 and RxD for P0.1
U0LCR = 0x83;// 8 bits, no Parity, 1 Stop bit
U0DLM = 0x00;
U0DLL = 0x61;
U0FCR = 0X07;//ENABLE FIFO
U0TER = 0X80;
U0LCR = 0x03;//to lock mul and div value
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?