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.

MSP430 串口操作发送数据,PC读发生overrun 错误



我最近写一个读芯片数据通过串口发送给上位机,读到一个串口发送一个,上位机读取过程中发生An overrun error occurred during transfer. A character was not read from the hardware before the next character arrived.错误,

下面是我的设置,请问怎么设置可以避免上述错误?

void Init_Uart(void)
{
//Set UCSWRST
UCA1CTL1_bit.UCSWRST_A1 = 1;
UCA1CTL1 = 0x81;
UCA1BRW = 0x40;            //7.3728M 115200baud


//Config port
P4SEL |= BIT4 + BIT5;
//Clear UCSWRST
UCA1CTL1_bit.UCSWRST_A1 = 0;

//Enable interrupt
UCA1IE_bit.UCRXIE_A1 = 1;
UCA1IE_bit.UCTXIE_A1 = 0;
return;
}

uchar Uart_TxByte(uchar hexchar)
{
while (!UCA1IFG_bit.UCTXIFG_A1);
UCA1TXBUF = hexchar;
return hexchar;
}

  • 这个错误是上位机提示的?还是你调试MSP430提示的?

    uchar Uart_TxByte(uchar hexchar)
    {
    while (!UCA1IFG_bit.UCTXIFG_A1);
    UCA1TXBUF = hexchar;
    return hexchar; 
    }

    1. 需要检查这个函数调用得是否太频繁了?

    2. 另外这个函数写的太奇怪了,形参又是返回结果,有必要这么写么?

  • 这个返回参数是顺手写的,完全可以优化掉;

    这个问题确实是上位提示的,我觉得只要是下位发送的太快,如果我发送完毕加延时

    uchar Uart_TxByte(uchar hexchar)
    {
    while (!UCA1IFG_bit.UCTXIFG_A1);
    UCA1TXBUF = hexchar;

    delayus(200);
    return hexchar; 
    }

    这样就可以,但是这影响我上位机等待的时间,对不同的波特率,怎么合理设置这个时间又是个问题,所以有没有别的办法判断或者有啥设置解决这个问题