打印

HC32F003C4Pa

[复制链接]
836|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
用官网例程UART1 改UART0 只能发生不能接受。不知到什么情况。long:

//串口引脚配置
static void App_PortInit(void)
{
    stc_gpio_cfg_t stcGpioCfg;

    DDL_ZERO_STRUCT(stcGpioCfg);

    Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE); //使能GPIO模块时钟

    ///<TX
    stcGpioCfg.enDir = GpioDirOut;
    Gpio_Init(GpioPort1, GpioPin4, &stcGpioCfg);
    Gpio_SetAfMode(GpioPort1, GpioPin4, GpioAf6);          //配置P35 端口为URART1_TX

    ///<RX
    stcGpioCfg.enDir = GpioDirIn;
    Gpio_Init(GpioPort1, GpioPin5, &stcGpioCfg);
    Gpio_SetAfMode(GpioPort1, GpioPin5, GpioAf5);          //配置P36 端口为URART1_RX
}

static void _UartBaudCfg(void)
{
    uint16_t timer=0;

    stc_uart_baud_cfg_t stcBaud;
    stc_bt_cfg_t stcBtCfg;

    DDL_ZERO_STRUCT(stcBaud);
    DDL_ZERO_STRUCT(stcBtCfg);

    //外设时钟使能
    Sysctrl_SetPeripheralGate(SysctrlPeripheralBt,TRUE);//模式0/2可以不使能
    Sysctrl_SetPeripheralGate(SysctrlPeripheralUart0,TRUE);

    stcBaud.bDbaud  = 0u;//双倍波特率功能
    stcBaud.u32Baud = 9600u;//更新波特率位置
    stcBaud.enMode  = UartMode3; //计算波特率需要模式参数
    stcBaud.u32Pclk = Sysctrl_GetPClkFreq(); //获取PCLK
    timer = Uart_SetBaudRate(M0P_UART0, &stcBaud);

    stcBtCfg.enMD = BtMode2;
    stcBtCfg.enCT = BtTimer;
    Bt_Init(TIM0, &stcBtCfg);//调用basetimer1设置函数产生波特率
    Bt_ARRSet(TIM0,timer);
    Bt_Cnt16Set(TIM0,timer);
    Bt_Run(TIM0);

}


static void App_UartInit(void)
{
    stc_uart_cfg_t  stcCfg;

    _UartBaudCfg();

    stcCfg.enRunMode = UartMode3;//测试项,更改此处来转换4种模式测试
    Uart_Init(M0P_UART0, &stcCfg);

    ///< UART中断配置
    Uart_EnableIrq(M0P_UART0, UartRxIrq);
    Uart_ClrStatus(M0P_UART0, UartRC);
    EnableNvic(UART0_IRQn, IrqLevel3, TRUE);

}
/******************************************************************************
* EOF (not truncated)
*********************
///< UART0 中断服务函数
void Uart0_IRQHandler(void)
{

                //delay1ms(500);
    if(TRUE == Uart_GetStatus(M0P_UART0, UartRC))
    {
        Uart_ClrStatus(M0P_UART0, UartRC);

        u8RxData[1] = Uart_ReceiveData(M0P_UART0);
        u8Rx** = 1;
    }

}


使用特权

评论回复

相关帖子

沙发
longzhengbing1|  楼主 | 2021-1-15 09:38 | 只看该作者
问题解决 官方文档中功能复用说明中国的配置 和端口寄存器中复用功能描述不一致,引起误导

1610674396(1).jpg (287.46 KB )

1610674396(1).jpg

1610674548(1).jpg (53.34 KB )

1610674548(1).jpg

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

5

帖子

1

粉丝