I'm aware that this question might have come up before, but I am unable to find my solution. I've got a PIC16f628 interfacing to a GSM module, in my C code I send the "at" command and then receive the result (which is supposed to be 'OK') using gets().
First I declare two char arrays:
char result[40], OK[3] = "OK';
then I send
printf("at");
putc(13);
then I try to receive and put into char result[40] using
gets(result);
NOW I try to compare the following:
if((strcmp(result, OK))==0)
{
//flash some LEDs
}
However, it always flashes the LEDs even if I change the OK[3] = "OK" to something else.
I can monitor data to and from the GSM module in hyperterminal, and the "at" does get received by the module, and it DOES return the "OK" result.
Can anyone please help me?
Thanks
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Mon Apr 16, 2007 11:53 am
Debug this problem by displaying the contents of the arrays (in hex)
right before the strcmp() statement. Use two for() loops to cycle through
each element of the two arrays and use "%x" to display elements in hex.
Then look at the results and make sure that the data that you think
should be there is really there. Also make sure that the incoming
data is really a string. A string will have ASCII characters followed
by a string terminator byte of 0x00.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum