103的板子这样改过,没问题,但是407的板子 ,修改串口2 不能发送数据!
void uart2_init(u32 bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);//
GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_USART2); //
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_USART2); //
//USART2_TX PA.2 PA.3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //
GPIO_Init(GPIOA,&GPIO_InitStructure); //
USART_InitStructure.USART_BaudRate = bound;//
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(USART2, &USART_InitStructure); //
USART_Cmd(USART2, ENABLE); //
USART_ClearFlag(USART2, USART_FLAG_TC);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//
//Usart1 NVIC ????
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------回复【9楼】正点原子:
---------------------------------
串口2的修改:
1 时钟
2 A2 A3
其他把USART1 改为USART2
但是 串口2 和3 无法通信
实在找不到原因。。
一周热门 更多>