stm32f103vct6的异步串口UART4和UART5,如下配置貌似只能发数据,不能收数据,连UART4_IRQHandler都进不去,求大神指点一二:
void drv_BT_UartInit(void){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE); //注意UART4是挂载在APB1总线上的,用 RCC_APB1PeriphClockCmd()函数初始化!
//configˉUART4-TX-PC10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//UART-RX-PC11
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
USART_InitStructure.USART_BaudRate = 57600;
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;
NVIC_SetPriority(UART4_IRQn,PRIORITY_UART4);
NVIC_EnableIRQ(UART4_IRQn);
USART_DeInit(UART4);
USART_Init(UART4, &USART_InitStructure);
USART_Cmd(UART4, ENABLE);
while(( UART4->SR & USART_FLAG_TC) == 0) __nop();
USART_ITConfig(UART4,USART_IT_RXNE,DISABLE);
hal_Uart_clear(UART4);
USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);
USART_ClearFlag(UART4,USART_FLAG_TC);
}
注:
void hal_Uart_clear(USART_TypeDef * pUart){
volatile int val;
if(pUart->SR & (USART_FLAG_RXNE|USART_FLAG_ORE)){
val=pUart->DR;
}else{
pUart->SR &= ~0x0F;
}
}
|