新手入门
- 积分
- 17
- 金钱
- 17
- 注册时间
- 2019-8-18
- 在线时间
- 5 小时
|

楼主 |
发表于 2019-8-29 14:01:01
|
显示全部楼层
void board_usart_init(USART_InitTypeDef* USART_InitStruct)
{
GPIO_InitTypeDef GPIO_InitStructure;
//Enable GPIO clock
RCC_AHBPeriphClockCmd(WOLF_COM1_TX_GPIO_CLK | WOLF_COM1_RX_GPIO_CLK, ENABLE);
// Enable USART clock
RCC_APB2PeriphClockCmd(WOLF_COM1_CLK, ENABLE);
// Connect PXx to USARTx_Tx
GPIO_PinAFConfig(WOLF_COM1_TX_GPIO_PORT, WOLF_COM1_TX_SOURCE, WOLF_COM1_TX_AF);
// Connect PXx to USARTx_Rx
GPIO_PinAFConfig(WOLF_COM1_RX_GPIO_PORT, WOLF_COM1_RX_SOURCE, WOLF_COM1_RX_AF);
//Configure USART Tx as alternate function
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = WOLF_COM1_TX_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(WOLF_COM1_TX_GPIO_PORT, &GPIO_InitStructure);
// Configure USART Rx as alternate function
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = WOLF_COM1_RX_PIN;
GPIO_Init(WOLF_COM1_RX_GPIO_PORT, &GPIO_InitStructure);
// USART configuration
USART_Init(WOLF_COM1, USART_InitStruct);
wolf_usart_NVIC_Config(); //Enable receive IT
//Enable USART
USART_Cmd(WOLF_COM1, ENABLE);
USART_ClearFlag(WOLF_COM1, USART_FLAG_TC);
}
上面是另一个串口1,设置一样,只是通讯口一组PA2, PA3,另一组是PA9,PA10,两个串口复用后单独通讯都没有问题,但不能循环使用
|
|