[应用相关] STM8S105K4 串口2 无奇偶校验,也能接收 偶校验的 数据

[复制链接]
 楼主| elephant00 发表于 2021-1-4 17:17 | 显示全部楼层 |阅读模式
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();
   }

}
不知道是不是 哪里设置错了
keaibukelian 发表于 2021-2-1 21:05 | 显示全部楼层
是不是硬件进行了校验啊
labasi 发表于 2021-2-1 21:09 | 显示全部楼层
可以无校验啊
paotangsan 发表于 2021-2-1 21:12 | 显示全部楼层
我觉得当然可以没有校验
renzheshengui 发表于 2021-2-1 21:16 | 显示全部楼层
如何知道是偶校验的数据呢
wakayi 发表于 2021-2-1 21:18 | 显示全部楼层
设置应该是没有错误的
wowu 发表于 2021-2-1 21:19 | 显示全部楼层
没有错误 啊   有一种校验是硬件校验
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1030

主题

3864

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部