Usart Receive and compare string
Discussion in "PIC Microcontroller Discussion" started by pravin_35 Aug 29, 2015.
Sat Aug 29 2015, 01:55 pm
Hi every one ,
I need a help how to compare the Usart receive data with constant String...
CODE:
the Port doesn't get toggled..
I need a help how to compare the Usart receive data with constant String...
CODE:
char *data=USARTReadData(); if(strcmp(data,"Start")==0) { PORTCbits.RC4 = 0; } else { PORTCbits.RC4 = 1; }
the Port doesn't get toggled..
Mon Aug 31 2015, 12:14 pm
can you provide code for "USARTReadData();" I doubt it will be returning you a string. from first thought I believe it should just return a character not a string.
Thu Sep 10 2015, 01:50 pm
can you provide code for "USARTReadData();" I doubt it will be returning you a string. from first thought I believe it should just return a character not a string.ajay_bhargav
char USARTReadData() { char data; //Check if q is empty if(UQFront==-1) return 0; data=URBuff[UQFront]; if(UQFront==UQEnd) { //If single data is left //So empty q UQFront=UQEnd=-1; } else { UQFront++; if(UQFront==RECEIVE_BUFF_SIZE) UQFront=0; } return data; }
Wed Sep 30 2015, 02:57 am
I am not sure you've solved it or not but "USARTReadData" only returns a byte not a string. so you first need to store data into a buffer until you get a \r or \n. for e.g.
char buffer[30]; char I, ch; I = 0; do { ch = USARTReadData(); if ((ch == '\r') || (ch == '\n')) { buffer[I++] = '\0'; break; } if (I == 29) { buffer[I] = '\0'; break; } } while (1); // Now you buffer has received a string you can process it as you want
pravin_35 like this.
Powered by e107 Forum System