按照串口1的驱动修改串口2 但串口2 无法使用 在线等 不应该呀!!!

2019-07-20 07:07发布

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); 
   
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
14条回答
caucyb
1楼-- · 2019-07-20 22:44
回复【7楼】正点原子:
---------------------------------
哪个例子  我怎么没找到,站长?407串口的例子是串口1  不是串口2呀
正点原子
2楼-- · 2019-07-21 04:26
回复【8楼】caucyb:
---------------------------------
485实验,GSM模块例程,蓝牙模块例程。都不是串口1啊。
caucyb
3楼-- · 2019-07-21 10:17
 精彩回答 2  元偷偷看……
caucyb
4楼-- · 2019-07-21 10:18
 精彩回答 2  元偷偷看……
caucyb
5楼-- · 2019-07-21 12:16
回复【9楼】正点原子:
---------------------------------回复【9楼】正点原子:
---------------------------------
串口2的修改:
1 时钟
A2 A3
其他把USART1 改为USART2 
但是 串口2 和3 无法通信
实在找不到原因。。
lovebird_27
6楼-- · 2019-07-21 13:04
 精彩回答 2  元偷偷看……

一周热门 更多>