如题。如果我去掉设置G口的引脚的话串口3就不能正常[mw_shl_code=applescript,true]void uart3_init(u32 bound){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource11,GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource10,GPIO_AF_USART3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
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(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//USART2 ????? 4 ?? ???
USART_InitStructure.USART_BaudRate = bound;//?????
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//???8?????
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(USART3, &USART_InitStructure); //?????2
USART_Cmd(USART3, ENABLE); //????2 6 ????
USART_ClearFlag(USART3, USART_FLAG_TC);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//?????? ??????? 5 ???? ???? NVIC
//Usart2 NVIC ??
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;//??1????
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//?????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ????
NVIC_Init(&NVIC_InitStructure); //??????????VIC????
}[/mw_shl_code]通讯,串口2也是这样的,我想问一下是为什么,如有知道请不吝赐教,谢谢啦
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
//串口3初始化
void UART3_Init()
{
USART_InitTypeDef USART_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
//PB10: USART3-TX
//PB11:USART3-RX
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;//USART3引脚
GPIO_Init(GPIOB, &GPIO_InitStruct);
USART_InitStruct.USART_BaudRate = 38400;//波特率38400
USART_InitStruct.USART_WordLength = USART_WordLength_8b;//8位数据
USART_InitStruct.USART_StopBits = USART_StopBits_1;//1位停止位
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//接收和发送使能
USART_InitStruct.USART_Parity = USART_Parity_No;//无校验
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无流控
USART_Init(USART3, &USART_InitStruct);//初始化串口3
NVIC_InitStruct.NVIC_IRQChannel = USART3_IRQn; //串口1中断
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 2; //主优先级
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1; //次级优先级
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; //使能中断
NVIC_Init(&NVIC_InitStruct);
USART_Cmd(USART3, ENABLE);//使能串口3
USART_ClearFlag(USART3, USART_FLAG_TC);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //打开串口3接收非空中断
}
这段代码是能够实现功能的,但是出去初始化G口的那几句代码就不能实现了,我问的就是这个啊
一周热门 更多>