void USART6_Config(u32 bound){
//GPIO配置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); //????GPIOC?±??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);//????USART6?±??
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6); //GPIOC6??????USART6
GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART6); //GPIOC7??????USART6
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //GPIOC6??GPIOC7
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//????????
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //????50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //???ì????????
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //????
GPIO_Init(GPIOC,&GPIO_InitStructure); //??????PC6??PC7
//USART6 ???????è??
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(USART6, &USART_InitStructure); //???????®??6
USART_Cmd(USART6, ENABLE); //?????®??6
USART_ClearFlag(USART6, USART_FLAG_TC);
}
void USART6_IT_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);//?????à??????
USART_ITConfig(USART6, USART_IT_TXE, ENABLE);
//Usart6 NVIC ????
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//?è????????????????·?×é2
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;//?®??6?????¨??
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//??????????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =2; //×???????2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????NVIC?????÷??
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>