|
- /********************************************************************************
- * FunctionName : bsp_InitUart(STM32_UART STM_UARTx,u32 baud)
- * Description : 初始化串口,未启用中断。
- * EntryParameter : uartNum - 串口(1~6), baud - 波特率
- * ReturnValue : 成功返回真,否则返回假
- *******************************************************************************/
- ComInitStatus bsp_InitUart(STM32_UART STM_UARTx,u32 baud) // usart3 init
- {
-
- USART_InitTypeDef USART_InitStructure;
- USART_TypeDef* COM[6]={USART1,USART2,USART3,UART4,UART5,USART6};
-
- if (STM_UARTx > STM_USART6)
- {
- return COM_ERROR;
- }
- else
- {
- Uart_SetGpio(STM_UARTx);
- //Uart_NVICConfig(STM_UARTx); Mask it !!
- USART_InitStructure.USART_BaudRate = baud; /* 波特率 */
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No ;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
-
- USART_Init(COM[STM_UARTx], &USART_InitStructure);
- USART_Cmd(COM[STM_UARTx], ENABLE); /* 使能串口 */
- USART_ClearFlag(COM[STM_UARTx], USART_FLAG_TXE); /* 清发送完成标志,Transmission Complete flag */
- }
- return COM_OK;
- }
复制代码 |
|