芯片是:STC8A8K64D4 。我用《09-串口4中断模式与电脑收发测试》demo出现问题,程序里面设置是115200波特率,而我串口助手设置成128000,才收到正确的数据。我的程序是仿真运行的。
-
-
- /******************* IO配置函数 *******************/
- void GPIO_config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure; //结构定义
-
- GPIO_InitStructure.Pin = GPIO_Pin_2 | GPIO_Pin_3; //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7
- GPIO_InitStructure.Mode = GPIO_PullUp; //指定IO的输入或输出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
- GPIO_Inilize(GPIO_P0,&GPIO_InitStructure); //初始化
- }
-
- /*************** 串口初始化函数 *****************/
- void UART_config(void)
- {
- COMx_InitDefine COMx_InitStructure; //结构定义
- COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
- COMx_InitStructure.UART_BRT_Use = BRT_Timer4; //选择波特率发生器, BRT_Timer2, BRT_Timer4 (注意: 串口2固定使用BRT_Timer2)
- COMx_InitStructure.UART_BaudRate = 115200ul; //波特率, 110 ~ 115200
- COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE
- UART_Configuration(UART4, &COMx_InitStructure); //初始化串口4 UART1,UART2,UART3,UART4
- NVIC_UART4_Init(ENABLE,Priority_1); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
-
- UART4_SW(UART4_SW_P02_P03); //UART4_SW_P02_P03,UART4_SW_P52_P53
- }
-
- /**********************************************/
- void main(void)
- {
- u8 i;
-
- EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
- GPIO_config();
- UART_config();
- EA = 1;
-
- printf("STC8 UART4 Test Programme!\r\n"); //UART4发送一个字符串
-
- while (1)
- {printf("STC8 UART4 Test Programme!\r\n");
- delay_ms(1000);
- if(COM4.RX_TimeOut > 0) //超时计数
- {
- if(--COM4.RX_TimeOut == 0)
- {
- if(COM4.RX_Cnt > 0)
- {
- for(i=0; i<COM4.RX_Cnt; i++) TX4_write2buff(RX4_Buffer[i]); //收到的数据原样返回
- }
- COM4.RX_Cnt = 0;
- }
- }
- }
- }
-
-
-
复制代码
|