hi every body
i have a problem with strstr function,
i receive characters from uart with interrupt & save them on the n length array(buffer array),
then in main loop i check buffer with strstr function from string.h for finding a special arrayof characters(for example" hello"),it works fine for the first time but some time it dosent work and without receiving that array of string it act like when find matching.
sample code :
interrupt handler ,when character received,it save that in the buffer:
main loop:
in some primary matching it works fine (when i type "hello",it return "1234") but after some tries it permanently return "1234" without matching
I've only taken a brief look at your code, therefore there maybe other issues, however one statement particularly grabs my attention which I've highlighted in red:
Once the string_pointer variable is set to NULL, code execution essentially stalls permanently executing that while loop in red, unless of course there is another ISR not shown which then changes the value contain in the string_pointer variable to something other than NULL.
Perhaps, a better strategy would be to enclose the code you do not want to run when a NULL is return and change the conditional:
Also, you appear to have a dangling "do" in your code, I can only assume there is a while() closing the do while loop missing from the code snippet.
You should also keep in mind, using software delays in conjunction with ISRs should typically be avoided, there usually other more appropriate and effective methods to regulate the speed of UART character transmission.
I'm guessing, that you want transmit some instructions and parse it at the receiver side.
Then you should work with instruction delimiters.
Example:
Let's say the delimiter is [CrLf]
Now if your receive buffer includes data like this: "d 123; 45 [CrLf]Write 45; 34 [CrLf]Write 6"
Do a search on the first [CrLf], move the data to the parse_string.
Now receive buffer:"Write 45; 34 [CrLf]Write 6"
Parse_string:"d 123; 45 [CrLf]"
Check the parse_string only. Here you may find the data is incomplete, garbage. So delete it
Do a new search on the first [CrLf], move the data to the parse_string.
Now receive buffer:"Write 6"
Parse_string:Write 45; 34 [CrLf]"
Check the parse_string only. Here you may find the data is complete and you could process the instruction. Write data 34 to address 45
Do a new search on the first [CrLf]
No [CrLf] found. So the instruction is not yet complete. Leave the receive buffer unchanged.
Leave the parse routine and wait for new data to receive.