This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

READ UART PROBLEM

Have problem with UART4 chanel , after try to read data , mcu stuck , debug simply does not show where ...

sample of code

#define UART4TIMEOUT 100000
unsigned char read_uart4 (unsigned char *rx_buff , unsigned char size)
{
    unsigned char count=0;
    unsigned char timeout=0;

    if(ROM_UARTCharsAvail(UART4_BASE)==false) return count;
    while ((count < size)||(timeout < UART4TIMEOUT))
    {

        if (ROM_UARTCharsAvail(UART4_BASE))
        {
            SysCtlDelay(900000);
            rx_buff[count++]=ROM_UARTCharGetNonBlocking(UART4_BASE);//ROM_UARTCharGet(UART4_BASE);//ROM_UARTCharGetNonBlocking(UART4_BASE);
            timeout=0;
        }else
            timeout++;
    }
return count;
}


This function use for many other platfor whidout any problem ...

  • Hello Kresmir,

    Though the post does not detail what the UART configuration, line state or the data being transmitted, but seems to be the issue in the while loop..

    while ((count < size)||(timeout < UART4TIMEOUT))

    Regards
    Amit
  • Hello Amit

    Thank you for answer .

    Uart set up on 115200  , n,8,1.

    I focused on  :

    "if (ROM_UARTCharsAvail(UART4_BASE))"

    on this line mcu stop work....

    Why you thing that while loop have problem like:

    "while ((count < size)||(timeout < UART4TIMEOUT)) "

    even count or timeout regular increase until reach limit...

    ?

    best regards

    Krešimir

  • Hello Kresmir,

    Even when timeout reaches UART4TIMEOUT, but the count is less than size, it shall remain in the loop

    Regards
    Amit
  • Thank you ,

    Understand timeout problem from sample.

    But main problem is

    "if (ROM_UARTCharsAvail(UART4_BASE))"

    To solve this problem , need to use

    uartrx interrupt

    and

    " volatile unsigned char rx_receive"     variable.

    interrupt will set "rx_receive=true" and

    my readuart function will set "rx_receive=false"

    it look like :

    volatile unsigned char rx_receive;

    #define MAXTIMEOUT  100

    volatile unsigned int timeout;

    ...

    uart_interrupt()

    {

    ...//clear interrupt flag etc...

    rx_receive=true;

    }

    ...

    read_uart(buff , size)

    {

     unsigned char count=0;

    if(rx_receive==false) return count;

    while(count < size)

    {

    if(rx_receive)

    {

    rx_receive=false;

    buff[count++]=get_char_non_block();

    timeout=MAXTIMEOUT;

    }

    if(timeout==0) return count;

    }

    return count;

    }

    systick()

    {

    ...

     if(timeout)timeout--;

    }

    finally , must edit interrupt list in startup file to install "uart_interrupt" at  UART4 base...

    also add "extern void uart_interrupt"  ...

    after all methode work like i want .

    Than you for help.

    Best regards

    Krešimir