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.

Trapped on line 1285 of uart.c

The function working fine with out the red color code, after add these code to the function it trapped on line 1285 of uart.c

I can't figure out how to fix that, did I made a mistake somewhere in the code? Thanks!

while(1)
{
while (UARTCharsAvail(UART3_BASE))
{

for(x=0; x<SIG_LEN; x++) {
UARTCharPut(UART4_BASE, sig[x]);
}
}

while (UARTCharsAvail(UART4_BASE))
{
rv[bitnum] = UARTCharGet(UART4_BASE);


if(bitnum >= 9)
{
bitnum = 0;}
else
{

bitnum ++;
}


if (bitnum == 8 )
{
realv[0]=(rv[3]-48)*10000+(rv[4]-48)*1000+(rv[5]-48)*100+(rv[6]-48)*10+(rv[7]-48);


UARTCharPut(UART3_BASE,realv[0]);
UARTCharPut(UART3_BASE,realv[1]);
UARTCharPut(UART3_BASE,realv[2]);

UARTprintf("%u00 PPM\n", realv[0]);
}
}

}



  • if I change the code inside the while loop, it traps at 1104 line of uart.c
    return((HWREG(ui32Base + UART_O_FR) & UART_FR_RXFE) ? false : true);

    while (UARTCharsAvail(UART3_BASE))
    {

    a = UARTCharGet(UART3_BASE);
    // for(x=0; x<SIG_LEN; x++) {
    // UARTCharPut(UART4_BASE, sig[x]);
    // }
    }
  • Hello Ben,

    Based on the second post of your code, what you are doing is correct. If data bytes are in the UART FIFO, then read the characters till it is emptied.

    If you are using optimization during compile, then change the optimization setting to "no optimization".

    Also check in the register window if the UARTFR register is showing RXFE as 0 or 1.
  • An issue I noticed:

    while (UARTCharsAvail(UART3_BASE))
    {
        for(x=0; x<SIG_LEN; x++) {
        UARTCharPut(UART4_BASE, sig[x]);
    }


    You are accessing two different UARTs (peripheral addresses) here. And I guess at least one of those is uninitialized, with no clock enabled, which will send you to the hardfault handler.

    Most probably a Copy&Paste error, since the combination in your code does not really make sense ...

  • Hello f.m.

    The same was covered in the next post

    a = UARTCharGet(UART3_BASE);