找回密码
 立即注册
查看: 21|回复: 0

我用《09-串口4中断模式与电脑收发测试》demo出现问题

[复制链接]
  • 打卡等级:初来乍到
  • 打卡总天数:6
  • 最近打卡:2025-10-31 09:52:22

11

主题

18

回帖

117

积分

注册会员

积分
117
发表于 前天 16:47 | 显示全部楼层 |阅读模式
芯片是:STC8A8K64D4 。我用《09-串口4中断模式与电脑收发测试》demo出现问题,程序里面设置是115200波特率,而我串口助手设置成128000,才收到正确的数据。我的程序是仿真运行的。


  1. /******************* IO配置函数 *******************/
  2. void        GPIO_config(void)
  3. {
  4.         GPIO_InitTypeDef        GPIO_InitStructure;                //结构定义
  5.         GPIO_InitStructure.Pin  = GPIO_Pin_2 | GPIO_Pin_3;                //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7
  6.         GPIO_InitStructure.Mode = GPIO_PullUp;        //指定IO的输入或输出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
  7.         GPIO_Inilize(GPIO_P0,&GPIO_InitStructure);        //初始化
  8. }
  9. /***************  串口初始化函数 *****************/
  10. void        UART_config(void)
  11. {
  12.         COMx_InitDefine                COMx_InitStructure;                                        //结构定义
  13.         COMx_InitStructure.UART_Mode      = UART_8bit_BRTx;                //模式,   UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
  14.         COMx_InitStructure.UART_BRT_Use   = BRT_Timer4;                        //选择波特率发生器,   BRT_Timer2, BRT_Timer4 (注意: 串口2固定使用BRT_Timer2)
  15.         COMx_InitStructure.UART_BaudRate  = 115200ul;                        //波特率,     110 ~ 115200
  16.         COMx_InitStructure.UART_RxEnable  = ENABLE;                                //接收允许,   ENABLE或DISABLE
  17.         UART_Configuration(UART4, &COMx_InitStructure);                //初始化串口4 UART1,UART2,UART3,UART4
  18.         NVIC_UART4_Init(ENABLE,Priority_1);                //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
  19.         UART4_SW(UART4_SW_P02_P03);                //UART4_SW_P02_P03,UART4_SW_P52_P53
  20. }
  21. /**********************************************/
  22. void main(void)
  23. {
  24.         u8        i;
  25.         EAXSFR();                /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
  26.         GPIO_config();
  27.         UART_config();
  28.         EA = 1;
  29.        
  30.         printf("STC8 UART4 Test Programme!\r\n");        //UART4发送一个字符串
  31.         while (1)
  32.         {printf("STC8 UART4 Test Programme!\r\n");
  33.                 delay_ms(1000);
  34.                 if(COM4.RX_TimeOut > 0)                //超时计数
  35.                 {
  36.                         if(--COM4.RX_TimeOut == 0)
  37.                         {
  38.                                 if(COM4.RX_Cnt > 0)
  39.                                 {
  40.                                         for(i=0; i<COM4.RX_Cnt; i++)        TX4_write2buff(RX4_Buffer[i]);        //收到的数据原样返回
  41.                                 }
  42.                                 COM4.RX_Cnt = 0;
  43.                         }
  44.                 }
  45.         }
  46. }
复制代码


回复

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-11-2 20:20 , Processed in 0.137085 second(s), 44 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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