/**
* Rx complete interrupt handler
*/
void NAKED SIG_UART_RECV(void);
void SIG_UART_RECV(void){
into_critical();
prologue();
if (!(uart.status & UART_RECVDATA)){
uart.status |= UART_RECVDATA;
if (uart.hook != NULL) uart.hook(uart.status);
}
if (!(UCSRA & (_BV(FE) | _BV(DOR)))){
unsigned char b = UDR;
int err = fifo_putbyte(uart.rxbuf, b);
if (err == -1){
uart.status |= UART_RX_FULLY;
if (uart.hook != NULL) uart.hook(uart.status);
}
}
epilogue();
}
应改为:
/**
* Rx complete interrupt handler
*/
void NAKED SIG_UART_RECV(void);
void SIG_UART_RECV(void){
into_critical();
prologue();
if (!(uart.status & UART_RECVDATA)){
uart.status |= UART_RECVDATA;
if (uart.hook != NULL) uart.hook(uart.status);
}
unsigned char tmp = UCSRA;
unsigned char b = UDR;
if (!(tmp & (_BV(FE) | _BV(DOR)))){
unsigned char b = UDR;
int err = fifo_putbyte(uart.rxbuf, b);
if (err == -1){
uart.status |= UART_RX_FULLY;
if (uart.hook != NULL) uart.hook(uart.status);
}
}
epilogue();
}
原来的代码在出现祯错误或奇偶错后,没有读UDR来消除错误,这样通常会在通信电缆插拔时带来意想不到的问题。
阅读(1526) | 评论(0) | 转发(0) |