今天,在调试项目的时候,遇到设置串口2波特率为19200的时候,USART_SetBaudrate(M4_USART2, 19200)函数返回 ErrorInvalidParameter,导致程序陷入了死循环,配置程序如下:
void USART2_LIN_Config(void){
#ifdef LIN_EN
#ifdef HC32_MCU
stc_usart_uart_init_t stcInitCfg;
en_result_t enRet;
stcInitCfg.enClkDiv = UsartClkDiv_1;
stcInitCfg.enClkMode = UsartIntClkCkNoOutput;
stcInitCfg.enDataLength = UsartDataBits8;
stcInitCfg.enDirection = UsartDataLsbFirst;
stcInitCfg.enStopBit = UsartOneStopBit;
stcInitCfg.enParity = UsartParityNone;
stcInitCfg.enSampleMode = UsartSamleBit8;
stcInitCfg.enDetectMode = UsartStartBitFallEdge;
stcInitCfg.enHwFlow = UsartRtsEnable;
enRet = USART_UART_Init(M4_USART2, &stcInitCfg);
if (enRet != Ok)
{ while (1); }
enRet = USART_SetBaudrate(M4_USART2, 19200);
if (enRet != Ok)
{ while (1); }
USART_FuncCmd(M4_USART2, UsartRx, Enable);
USART_FuncCmd(M4_USART2, UsartTx, Enable);
USART_FuncCmd(M4_USART2, UsartRxInt,Enable);
#endif
#endif
}
|