#define USART5_BL USART2
#define USART5_BL_GPIO GPIOA
#define USART5_BL_CLK RCC_APB1_PERIPH_USART2
#define USART5_BL_GPIO_CLK RCC_APB2_PERIPH_GPIOA
#define USART5_BL_RxPin GPIO_PIN_3
#define USART5_BL_TxPin GPIO_PIN_2
#define USART5_BL_Rx_GPIO_AF GPIO_AF0_USART2
#define USART5_BL_Tx_GPIO_AF GPIO_AF0_USART2
#define USART_BL_IRQH USART2_IRQn
#define GPIO_APBxClkCmd RCC_EnableAPB2PeriphClk
#define USART_BL_APBxClkCmd RCC_EnableAPB1PeriphClk
//串口2初始化,因为是在串口5上直接改来测试,请不要纠结名字。
void uart5_configuration(void)
{
GPIO_InitType GPIO_InitStructure;
USART_InitType USART_InitStructure;
NVIC_InitType NVIC_InitStructure;
DMA_InitType DMA_InitStructure_rx;
GPIO_InitStruct(&GPIO_InitStructure);
/* Enable GPIO clock */
GPIO_APBxClkCmd(USART5_BL_GPIO_CLK, ENABLE);
/* Enable USARTx Clock */
USART_BL_APBxClkCmd(USART5_BL_CLK, ENABLE);
/* Configure USARTx Tx as alternate function push-pull */
GPIO_InitStructure.Pin = USART5_BL_TxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Alternate = USART5_BL_Tx_GPIO_AF;
GPIO_InitPeripheral(USART5_BL_GPIO, &GPIO_InitStructure);
/* Configure USARTx Rx as alternate function push-pull and pull-up */
GPIO_InitStructure.Pin = USART5_BL_RxPin;
// GPIO_InitStructure.GPIO_Pull = GPIO_Mode_Input;//GPIO_Pull_Up;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Input;
GPIO_InitStructure.GPIO_Alternate = USART5_BL_Rx_GPIO_AF;
GPIO_InitPeripheral(USART5_BL_GPIO, &GPIO_InitStructure);
USART_InitStructure.BaudRate = 9600;
USART_InitStructure.WordLength = USART_WL_8B;
USART_InitStructure.StopBits = USART_STPB_1;
USART_InitStructure.Parity = USART_PE_NO;
USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
USART_InitStructure.Mode = USART_MODE_RX | USART_MODE_TX;
USART_Init(USART5_BL, &USART_InitStructure);
USART_ConfigInt(USART5_BL, USART_INT_RXDNE, ENABLE); //使能串口5接收中断
//USART_ConfigInt(USART5_BL, USART_INT_IDLEF, ENABLE); //使能串口5空闲中断
/* Clear USART send flag */
//USART_ClrFlag(USART5_BL, USART_FLAG_RXDNE);
//USART_ClrFlag(USART5_BL, USART_FLAG_IDLEF);
NVIC_InitStructure.NVIC_IRQChannel = USART_BL_IRQH; //设置UART5中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Enable(USART5_BL, ENABLE);
}
//服务函数,现在中断进不去,而且接收管脚一旦外接GPS模块,电平就很低了。
void USART2_IRQHandler(void)
{
if (USART_GetIntStatus(USART5_BL, USART_INT_RXDNE) != RESET)
{
g_uart5_buf[uart5_rcv_cnt++] = USART_ReceiveData(USART5_BL);
// USART_ClrFlag(USART5_BL, USART_FLAG_RXDNE);
printf("g_uart5_buf rcv: %s len: %d \r\n", g_uart5_buf, g_uart_rec_len);
}
if (uart5_rcv_cnt >= 200)
{
uart5_rcv_cnt = 0;
printf("uart5 rcv: %s\r\n", g_uart5_buf);
}
}
问题:请问 是配置的不对吗? 串口5是正常的使用的,但是串口2 PA2-TXD PA3-RXD 就用不起来,有人遇到过吗? ,GPS有3v左右,一接上RXD——PA3引脚就被拉低了.
|