dizgah
Member level 5
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 used stm32 & keil
thanks for any help
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:
Code:
void USART1_IRQHandler(void)
{
/* RXNE handler */
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
Rx_Buffer[Counter_Num1]=(char)USART_ReceiveData(USART1);
Counter_Num1++;
if(Counter_Num1==100)
{
Counter_Num1=0;
}
}
}
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
Code:
while(1)
{
//--------------------------------------
do
string_pointer = strstr (Rx_Buffer, "hello");
while(string_pointer==NULL);
USART_SendData(USART1, '1');
delay_ms(50);
for(loop_counter=0;loop_counter<100;loop_counter++)
{
Rx_Buffer[loop_counter]=' ';
}
string_pointer=NULL;
USART_SendData(USART1, '2');
delay_ms(50);
USART_SendData(USART1, '3');
delay_ms(50);
USART_SendData(USART1, '4');
delay_ms(50);
//-----------------------------------
}
thanks for any help
Last edited: