cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

New Contributor II

Uart Rx interrupt ISR stopped after receive data at the first time. Attach code, please check and tell me what's the problem.

thanks a lot!

0 Likes
Reply
1 Solution
Esteemed Contributor

Hi,

I would re-write GetRecv() like below

============================

uint32_t GetRecv()

{

    uint8_t  ch; /* changed to uint8_t */

    uint32_t size = 0;

    uint32_t real_size = 0;

    uint8_t  tmpBuffer[256];

     while(UART_SpiUartGetRxBufferSize()) {

          tmpBuffer[real_size++] = UART_UartGetChar() ;

          if (real_size >= sizeof(tmpBuffer)) {

               break ;

          }

     }

     if (real_size > 0) {

          size = WriteRingBuffer(tmpBuffer, real_size, &s_RingBuffer);

     }

     return size ;

}

============================

If it does not work, I'm sorry (in advance).

moto

View solution in original post

5 Replies
Honored Contributor II

Check UART P4 examples in this thread and link inside

Re: UART Input String Parsing

0 Likes
Reply
Esteemed Contributor

Hi,

I would re-write GetRecv() like below

============================

uint32_t GetRecv()

{

    uint8_t  ch; /* changed to uint8_t */

    uint32_t size = 0;

    uint32_t real_size = 0;

    uint8_t  tmpBuffer[256];

     while(UART_SpiUartGetRxBufferSize()) {

          tmpBuffer[real_size++] = UART_UartGetChar() ;

          if (real_size >= sizeof(tmpBuffer)) {

               break ;

          }

     }

     if (real_size > 0) {

          size = WriteRingBuffer(tmpBuffer, real_size, &s_RingBuffer);

     }

     return size ;

}

============================

If it does not work, I'm sorry (in advance).

moto

View solution in original post

New Contributor II

Thank you very much for your guidance. I tried it and the result looks good. Thanks again!

New Contributor II

I check the code you post, there is little difference that add a condition before call UART_UartGetChar() , Is it because the function is called too often that the interrupt is unresponsive?

0 Likes
Reply
Esteemed Contributor

Hi,

UART_UartGetChar() returns 0 when no more char is available or an error arose.

But I feel accessing an empty buffer or when an error arose is not a good idea,

so I check the number of data available before accessing the buffer.

moto

0 Likes
Reply