Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Problem in reading string from UART

Status
Not open for further replies.

Mrunal Ahirrao

Full Member level 2
Full Member level 2
Joined
Nov 26, 2012
Messages
133
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
India
Visit site
Activity points
2,213
Hi everyone,
I am reading a string as response from SIM 300 GSM module. The string transmitted by GSM module is "RING" so I am using UART1_Read_text library function.I am using PIC16F628A and I am able to send SMS, dial calls etc,but as a beginner in serial communication I am unable to read/ detect the RING indicator from SIM300. Any help would be highly appreciated.I am using MikroC Pro for PIC and Here is my code:
Code:
/* Testing connection with SIM300*/

sbit LED at RB4_bit;
//char receive;
char RX[]=;
//char SR[];
//unsigned short i;



void main()
{
CMCON=0x07;
TRISA=0;
TRISB=0b00000010;
LED=0;
/*output[1]=' ';
output[2]=' ';
output[3]=' ';
output[4]=' ';*/

delay_ms(60000);//delay to let SIM300 ready
UART1_Init(9600);
UART1_Write_Text("AT\r");
Delay_ms(2000);
while(1)
{
if(UART1_Data_Ready() == 1)
{

UART1_Read_Text(&RX,"\r\n",6);
}
Delay_ms(2000);
if((RX[1]=='R')&&(RX[2]=='I')&&(RX[3]=='N')&&(RX[4]=='G'))
{
UART1_Write_Text("ATH\r");
LED=~LED;
RCREG=0;    //Set receive registry to zero
}
}
}
 

what is the format of data send from GSM?.
You had given a delimitter \r\n. Is the message send from GSM ends with the same \r\n?
also u initialized RX, but why you store the received data to &RX?

UART1_Read_Text(&RX,"\r\n",6);
this instruction will check for a data that ends with \r\n and store it in &RX.
I think that you should check for the data format send from GSM ,or make it to end with \r\n.
Also store the received data to RX
 

what is the format of data send from GSM?.
You had given a delimitter \r\n. Is the message send from GSM ends with the same \r\n?
also u initialized RX, but why you store the received data to &RX?

UART1_Read_Text(&RX,"\r\n",6);
this instruction will check for a data that ends with \r\n and store it in &RX.
I think that you should check for the data format send from GSM ,or make it to end with \r\n.
Also store the received data to RX

Actually I don't know the GSM format for data but with much try I have succeeded in comparing two strings for equality. And I have used RX array for storing the received string UART and then comparing it with predefined string. Here is my modified code:
Code:
/* Testing connection with SIM300*/

sbit LED at RB4_bit;
//char receive;
char RX[]=;
//char SR[];
//unsigned short i;



void main()
{
CMCON=0x07;
TRISA=0;
TRISB=0b00000010;
LED=0;
/*output[1]=' ';
output[2]=' ';
output[3]=' ';
output[4]=' ';*/

delay_ms(60000);//delay to let SIM300 ready
UART1_Init(9600);
UART1_Write_Text("AT\r");
Delay_ms(2000);
while(1)
{
if(UART1_Data_Ready() == 1)
{

UART1_Read_Text(&RX,"\r\n",6);
}
Delay_ms(2000);
for(i=0;i<5;i++)  //string length is 5
{
   if(SR[i]==RX[i])    //here a[] is the string which is received through uart and x[] is predefined string
   {
      b++;        //increment b value by one
   }
}
if(b==5)
{
 b=0;
UART1_Write_Text("ATH\r");
LED=~LED;//write your output
}

Now the LED which is LED=0 before turn to LED=1 when I call, but now problem is When I again called then now it is LED=1 and should be inverted i.e LED=0; but its not working...

- - - Updated - - -

Check for delimiter "OK\r\n"

Now I am able to work with it milan but now its not working by program as I have replied to rado...
 

char RX[]=; looks very suspicious to me.

What is it supposed to be declaring, a single char or an array. If it's an array what size is it supposed to be?
Try 'char *RX[] = {0};' or 'char RX[size];'

It would still be useful to look for a line terminator such as CR than actual text. What happens for example if it returns 'Error' instead of 'Ring'?

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top