请选择 进入手机版 | 继续访问电脑版
搜索
查看: 714|回复: 3

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

[复制链接]

该用户从未签到

2

主题

5

帖子

0

蝴蝶豆

初级会员

最后登录
2020-12-17
发表于 2020-6-10 08:39:59 | 显示全部楼层 |阅读模式
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();
   }

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


回复

使用道具 举报

该用户从未签到

2

主题

5

帖子

0

蝴蝶豆

初级会员

最后登录
2020-12-17
 楼主| 发表于 2020-6-10 10:42:02 | 显示全部楼层
都没人碰到过吗?
回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

77

帖子

0

蝴蝶豆

中级会员

最后登录
2021-3-15
发表于 2020-11-20 19:12:33 | 显示全部楼层
去里有贴专讲这个的,里面有一个PDF文件,你细看一下
回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

77

帖子

0

蝴蝶豆

中级会员

最后登录
2021-3-15
发表于 2020-11-20 19:15:10 | 显示全部楼层
文件名就叫STM8S中的UART奇偶校验的使用方法
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|论坛-意法半导体STM32/STM8技术社区

GMT+8, 2024-4-19 00:43 , Processed in 0.155718 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表