#if(USART4)
USART_DeInit(UART4);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); //使能端口C时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure); //PC11-RXD4
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure); //PC10-TXD4为推挽复用输出
Txd4_Cnt=Txd4_len=Txd4_timer=0;
Rxd4_Cnt=Rxd4_len=Rxd4_timer=Flags1.Rxd4Over=0;
USART_InitStructure.USART_BaudRate = UART4_BaudRate;
USART_InitStructure.USART_WordLength = (UART4_WordLen/9) << 12;
USART_InitStructure.USART_Parity = UART4_PCE << 10;
USART_InitStructure.USART_Parity |= UART4_PS << 9;
USART_InitStructure.USART_StopBits = UART4_StopBit << 12;
USART_InitStructure.USART_Mode = (UART4_RxEn<<2) | (UART4_TxEn<<3);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE); //使能UART4时钟
USART_Init(UART4, &USART_InitStructure);
// UART4->CR1 |= UART4_TxEIE << 7;
// UART4->CR1 |= UART4_RxNEIE << 6;
UART4->CR1 |= USART4 << 13; //使能USART4
#endif
|