你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM8S105K4 串口2 无奇偶校验,也能接收 偶校验的 数据

[复制链接]
阿里汤烫 提问时间:2020-6-10 08:39 /
MCU STM8S105K4    设置为一个起始为,8个数据位,无校验,一个停止位,用串口助手 发送能够 接收的数据,还是正确的,
static void UART_Config(void)
UART2_DeInit();
       UART2_Init((uint32_t)9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO,
        UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE);
     }

      /* Enable the UART Receive interrupt: this interrupt is generated when the UART
    receive data register is not empty */
     UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);

     /* Enable UART */
     UART2_Cmd(ENABLE);
     /* Enable general interrupts */
     enableInterrupts();

中断接收
INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21)
{
    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
     unsigned char temp=0;
    unsigned char temp_state=0;
    /* Read one byte from the receive data register */
  
/*   temp_state=UART2->SR;
       if(temp_state&0x01)                         // 奇偶 ERROR
     {
       temp=8;
      UART2_ReceiveData8();
      //return;
    }
    else*/
   
    temp_state=UART2->SR;
       if((temp_state&0x01)!=1)
     //if(UART2_GetITStatus(UART2_IT_PE) == RESET)
     {
        temp=UART2_ReceiveData8();
   }

}
不知道是不是 哪里设置错了


收藏 评论3 发布时间:2020-6-10 08:39

举报

3个回答
阿里汤烫 回答时间:2020-6-10 10:42:02
都没人碰到过吗?
jesseqiao 回答时间:2020-11-20 19:12:33
去里有贴专讲这个的,里面有一个PDF文件,你细看一下
jesseqiao 回答时间:2020-11-20 19:15:10
文件名就叫STM8S中的UART奇偶校验的使用方法
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版