best way of monitoring usart protocol for finding & storing of a desire characters

Status
Not open for further replies.

dizgah

Member level 5
Joined
Nov 8, 2009
Messages
91
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
iran-8par
Activity points
2,049
best way of monitoring & capturing usart protocol for find & storing of a character

hi every one
is there any special function for this purpose ?
i am currently read characters byte by byte and compare them with desire character but i dont know why it does not work some time
my way :
Code:
do
R_Buffer=usart_reci(1);//function of receiving characters from usart 1 its work correctly
while( R_Buffer=='o'| R_Buffer=='O');
best regards
 

Re: best way of monitoring usart protocol for finding & storing of a desire character

Read each byte inside uart-rx interrupt, increase reseived byte counter, use a timer with interrupt to check when package will end, in main loop check ready flag and determine received data. Timer should overflow after 1,5 bytes receive time.
STM8 example
Code:
INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)                                      //uart receive interrupt
{
  if (DataReceivedFlag == 0)
    if (inBufi<sizeof(inBuf))
    {
      inBuf[inBufi] = UART1->DR;
      inBufi++;
      TIM2->CNTRH = 0;
      TIM2->CNTRL = 0;
      TIM2->CR1 |= TIM2_CR1_CEN;
    }
  UART1->SR&= ~UART1_SR_RXNE;                                                   //clear IT pending bit
}

INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)                              //tim2 RX timeout interrupt
{
  TIM2->CR1 &= ~TIM2_CR1_CEN;
  DataReceivedFlag = ENABLE;
  TIM2->SR1 &= ~TIM2_IT_UPDATE;
}
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…