One method would be to use the UARTx_Read and the UARTx_Data_Ready commands to monitor if an incoming byte has been received. This requires that you test each incoming byte to see if it matches the characters you are looking for. This is still a "blocking function" but it is more flexible in dealing with the WDT.
Code: Select all
unsigned char testString [2] = {'*', '!'};
unsigned char i = 0;
unsigned char receive = 0;
do
{
if (UART1_Data_Ready() != 1) asm clrwdt; // loop until byte is received, clear WDT
receive = UART1_Read(); // read imcoming byte
if (receive == testString[i]) i++; // test for character match. if true index array for next character compare.
else i = 0; // if false, reset array index and try again.
} while (i != 2); // loop until all chars found, exit
The most efficient way to do this would be to utilize UART interrupts and service each incoming byte as it arrives allowing you to perform other tasks while waiting (including WDT clearing). Doing so prevents the search routine from becoming a blocking function.