找回密码
 立即注册
查看: 759|回复: 4

STC8H3K32S2串口3卡死在while(COM3.B_TX_busy);

[复制链接]
  • 打卡等级:初来乍到
  • 打卡总天数:5
  • 最近打卡:2024-07-12 18:14:20

3

主题

18

回帖

111

积分

注册会员

积分
111
发表于 2023-10-19 17:45:25 | 显示全部楼层 |阅读模式
代码如下
#include "config.h"
#include "STC8G_H_GPIO.h"
#include "STC8G_H_UART.h"
#include "STC8G_H_NVIC.h"
#include "STC8G_H_Delay.h"
#include "STC8G_H_Switch.h"

#define LED P32

void GPIO_config(void)
{
        GPIO_InitTypeDef        GPIO_InitStructure;                //结构定义
        GPIO_InitStructure.Pin  = GPIO_Pin_0 | GPIO_Pin_1;                //指定要初始化的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);        //初始化
       
        GPIO_InitStructure.Pin  = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;                //指定要初始化的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_P3,&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_Timer1;                        //选择波特率发生器, BRT_Timer1, BRT_Timer2 (注意: 串口2固定使用BRT_Timer2)
        COMx_InitStructure.UART_BaudRate  = 115200ul;                        //波特率, 一般 110 ~ 115200
        COMx_InitStructure.UART_RxEnable  = ENABLE;                                //接收允许,   ENABLE或DISABLE
        COMx_InitStructure.BaudRateDouble = DISABLE;                        //波特率加倍, ENABLE或DISABLE
        UART_Configuration(UART1, &COMx_InitStructure);                //初始化串口1 UART1,UART2,UART3,UART4
        NVIC_UART1_Init(ENABLE,Priority_1);                //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
        UART1_SW(UART1_SW_P30_P31);                //UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17,UART1_SW_P43_P44
       
        COMx_InitStructure.UART_Mode      = UART_8bit_BRTx;                //模式,   UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
        COMx_InitStructure.UART_BRT_Use   = BRT_Timer3;                        //选择波特率发生器,   BRT_Timer2, BRT_Timer3 (注意: 串口2固定使用BRT_Timer2)
        COMx_InitStructure.UART_BaudRate  = 9600ul;                        //波特率,     110 ~ 115200
        COMx_InitStructure.UART_RxEnable  = ENABLE;                                //接收允许,   ENABLE或DISABLE
        UART_Configuration(UART3, &COMx_InitStructure);                //初始化串口 UART1,UART2,UART3,UART4
        NVIC_UART3_Init(ENABLE,Priority_1);                //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3

        UART3_SW(UART3_SW_P00_P01);                //UART3_SW_P00_P01,UART3_SW_P50_P51
}

int main(){
       
        EAXSFR();                /* 扩展寄存器访问使能 */
       
        GPIO_config();
        UART_config();
        EA = 1;
       
        while(1)
        {
                LED=0;
                delay_ms(500);
                LED=1;
                delay_ms(500);
                PrintString1("111\t");
                PrintString3("333\t");
               
        }
       
}

回复

使用道具 举报 送花

  • 打卡等级:初来乍到
  • 打卡总天数:5
  • 最近打卡:2024-07-12 18:14:20

3

主题

18

回帖

111

积分

注册会员

积分
111
发表于 2023-10-19 17:46:35 | 显示全部楼层
注释掉PrintString3可以打印串口1 不注释就会卡死在while(COM3.B_TX_busy);
回复 支持 反对

使用道具 举报 送花

  • 打卡等级:初来乍到
  • 打卡总天数:5
  • 最近打卡:2024-07-12 18:14:20

3

主题

18

回帖

111

积分

注册会员

积分
111
发表于 2023-10-19 17:52:04 | 显示全部楼层
以下是完整代码 求解 串口1可以用 串口3用不了

demo.zip

737.49 KB, 下载次数: 52

回复 支持 反对

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:55
  • 最近打卡:2025-05-02 08:32:59

718

主题

1万

回帖

1万

积分

管理员

积分
15630
发表于 2023-10-19 18:36:13 | 显示全部楼层
回复 支持 反对

使用道具 举报 送花

  • 打卡等级:初来乍到
  • 打卡总天数:5
  • 最近打卡:2024-07-12 18:14:20

3

主题

18

回帖

111

积分

注册会员

积分
111
发表于 2023-10-19 19:04:52 | 显示全部楼层
找到问题了 这个芯片只有2个串口没有串口3
回复 支持 反对

使用道具 举报 送花

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

本版积分规则

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

GMT+8, 2025-5-2 17:18 , Processed in 0.118785 second(s), 72 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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