串口的初始化
/**
* @brief 串口初始化
*
* @param USARTx 串口号
* @param u32Baudrate 波特率
*/
void Usart_Init(M4_USART_TypeDef *USARTx, uint32_t u32Baudrate)
{
stc_irq_regi_conf_t stcIrqRegiCfg;
uint32_t u32Fcg1Periph = PWC_FCG1_PERIPH_USART1 | PWC_FCG1_PERIPH_USART2 | \
PWC_FCG1_PERIPH_USART3 | PWC_FCG1_PERIPH_USART4;
stc_usart_uart_init_t stcInitCfg = {
UsartIntClkCkOutput,
UsartClkDiv_1,
UsartDataBits8,
UsartDataLsbFirst,
UsartOneStopBit,
UsartParityNone,
UsartSampleBit8,
UsartStartBitFallEdge,
UsartRtsEnable,
};
MEM_ZERO_STRUCT(stcIrqRegiCfg);
USART_DeInit(USARTx);
/* Initialize DMA */
Usart4DmaInit();
/* Initialize Timer0 */
Usart4Timer0Init();
/* Enable peripheral clock */
PWC_Fcg1PeriphClockCmd(u32Fcg1Periph, Enable);
PORT_DebugPortSetting(1<<2, Disable);
PORT_DebugPortSetting(1<<4, Disable);
/* Initialize USART IO */
PORT_SetFunc(LCD_USART_RX_PORT, LCD_USART_RX_PIN, LCD_USART_RX_FUNC, Disable);
PORT_SetFunc(LCD_USART_TX_PORT, LCD_USART_TX_PIN, LCD_USART_TX_FUNC, Disable);
/* Initialize UART */
USART_UART_Init(USARTx, &stcInitCfg);
/* Set baudrate */
USART_SetBaudrate(USARTx, u32Baudrate);
/* IRQ init */
Usart4IrqInit();
USART_FuncCmd(USARTx, UsartTimeOut, Enable); //
USART_FuncCmd(USARTx, UsartTimeOutInt, Enable); //
USART_FuncCmd(USARTx, UsartTx, Enable);
USART_FuncCmd(USARTx, UsartRx, Enable);
USART_FuncCmd(USARTx, UsartRxInt, Enable);
}
|