UART interruption

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I need to read the input from the UART.

   

Set the UART working as interruption mode.

   

RxBuf =4; TxBuf=40;

   

 

   

Then once Rx Recieve char 'a' need to read another 16 bytes.

   

The problem is ,if read less than 8, it works fine, more than 8 it will report a strange value. 

   

I try to change the RxBuf to 16 not helping.

   

 

   

CY_ISR(UART_RX){
    ch = get_byte();
    if (0xffffu != ch)
    {
       if(ch=='a'){

   

        get_byte();

   

  .....

   

        get_byte();

   


       }

   

    }

   

}

   

uint16 get_byte(){
    uint16 ch = 0;
    uint16 _timeout=200;
    do{
        //if(UART_DEB_GetRxBufferSize()>0)
        {
            ch = UART_DEB_GetByte();
            if((ch&0xff00)==0){
               return ch&0xff;   
            }
        }
        _timeout--;
    }while(_timeout>0);    
    return 0xFFFF;
}

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your error is probably using UART_DEB_GetRxBufferSize() together with your own interrupt handler.

   

Waiting for some event happening within an interrupt handler should be strictly avoided, the system may stall for a longer time.

   

I would suggest:

   

increase Rx buffer size to ~40 bytes, you may do that for Tx buffer as well, use 2 times the expected transmit size.

   

do not use any interrupts and trust in the component's software

   

use UART_DEB_GetRxBufferSize() to poll for incoming lead in and later for the 16 chars.

   

Using your own interrupt and UART_DEB_GetRxBufferSize() does not work because that is maintained by the internal interrupt.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I can't using poll, I have to using the interruption, as I need deal with a 1us timer to record the time.

   

Any suggestion on using own interruption to receive bytes?

   

I change to the following, still not works.

   

uint8 get_byte(){
 while(UART_DEB_ReadRxStatus()&UART_DEB_RX_STS_FIFO_NOTEMPTY ){
    return UART_DEB_ReadRxData();        
 }   
 return 0;
}

   

 

   

CY_ISR(UART_RX){
    ....

   

    t_rx = current_us();

   

   for(i=0;i<5;i++){

   

     ....get_byte();

   

   } 

   

}

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When in trouble it is always best to provide us with a complete project archive. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I sloved this after change to check all the possible errors, then the problem solved.

   

BTW: No any error printed, I don't know why, but after that works perfect.

   

uint8 get_byte(){
    uint8 rxstatus;
    do{
        rxstatus = UART_DEB_ReadRxStatus();
        if(rxstatus&UART_DEB_RX_STS_PAR_ERROR) {}// UART_DEB_PutString("e1");
        else if(rxstatus&UART_DEB_RX_STS_STOP_ERROR){}// UART_DEB_PutString("e2");
        else if(rxstatus&UART_DEB_RX_STS_BREAK) {}// UART_DEB_PutString("e3");
        else if(rxstatus&UART_DEB_RX_STS_OVERRUN) {}//  UART_DEB_PutString("e4");
        else if(rxstatus&UART_DEB_RX_STS_ADDR_MATCH){}//  UART_DEB_PutString("e5");
        else if(rxstatus&UART_DEB_RX_STS_MRKSPC) {}//UART_DEB_PutString("e6");
        else if(rxstatus&UART_DEB_RX_STS_SOFT_BUFF_OVER) {}//UART_DEB_PutString("e7");
        else if(rxstatus&UART_DEB_RX_STS_FIFO_NOTEMPTY) return UART_DEB_ReadRxData();
    }while(1);
    return 0;
}

0 Likes