高级会员

- 积分
- 959
- 金钱
- 959
- 注册时间
- 2015-11-27
- 在线时间
- 109 小时
|
10金钱
//3õê¼»ˉIO ′®¿ú2
//bound:2¨ìØÂê
void uart2_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Enable the USART2 Pins Software Remapping */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB1Periph_USART2, ENABLE);
USART_DeInit(USART2);
/* Configure USART2 Tx (PA.02) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART2 Rx (PA.03) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable the USART2 Interrupt */
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);
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_ITConfig(USART2, USART_IT_RXNE, ENABLE);
//USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
/* Enable USART2 */
USART_Cmd(USART2, ENABLE);
}
这是用来初始化串口二的程序,串口一和串口三的程序也是类似的初始化操作,现在串口一和串口三都能工作, 就串口二不能工作
原以为是硬件的问题,换了一块mini开发板还是一样的问题,求大佬指导
|
最佳答案
查看完整内容[请看2#楼]
找到问题了,RCC_APB1Periph_USART2初始化错了,该用RCC_APB1PeriphClockCmd初始化
|