stm32w108 Hal_Driver库hal_uart.c的错误

今天调试stm32w108发现Hal_Driver库中hal_uart.c文件内有一处错误,会导致串口读取到无效数据。

原始中断函数如下

void halSc1Isr(void)

{
  uint32_t interrupt;
  /* this read and mask is performed in two steps otherwise the compiler
     will complain about undefined order of __IO access */
  interrupt = SC1_IT->ISR;
  interrupt &= SC1_IT->IER;
  while (interrupt != 0) {
    SC1_IT->ISR = interrupt; /* acknowledge the interrupts early */ /*这里清标志位不起作用*/
    /* RX events */
    if ( interrupt & (SC_IER_RXNEIE   | /* RX has data */
                      SC_IER_OVRIE   | /* RX Overrun error */
                      SC_IER_FEIE | /* RX Frame error */
                      SC_IER_PEIE ) /* RX Parity error */
       ) {
      halInternalUart1RxIsr();
    }
    
    /* TX events */
    if ( interrupt & (SC_IER_TXEIE | /* TX has room */
                      SC_IER_IDLEIE ) /* TX idle (more room) */
       ) {
      halInternalUart1TxIsr();
    }


    interrupt = SC1_IT->ISR;
    interrupt &= SC1_IT->IER;
  }
}


SC1_IT->ISR = interrupt;这句不能清RXNE,因为数据还没有被读取,即使清了标志位,芯片又自动会打上标志位,所以应该放到读取DR之后。对于TXE标志位也是如此。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值