STM32f103系列 PC11 RX USART3 问题
楼主最近使用f103rct6进行开发的时候,想使用PC10,PC11(对应USART3)进行USART通信,但是PC10正常发送,PC11无法正常接收。
————————————————————————————————————————————————
省流版解决方案
GPIO口正常配置GPIOC
USART配置正常配置USART3
加上端口部分重映射
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(BLUETOOTH_USART_GPIO_CLK, ENABLE);
RCC_APB1PeriphClockCmd(BLUETOOTH_USART_CLK, ENABLE);
**GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);**
//BLUETOOTH_USART_GPIO_CLK RCC_APB2Periph_GPIOC
//BLUETOOTH_USART_CLK RCC_APB1Periph_USART3
————————————————————————————————————————————————
完整代码模块
//.h file
#define BLUETOOTH_USARTx USART3
#define BLUETOOTH_USART_CLK RCC_APB1Periph_USART3
#define BLUETOOTH_USART_APBxClkCmd RCC_APB1PeriphClockCmd
#define BLUETOOTH_USART_BAUDRATE 115200
// USART GPIO
#define BLUETOOTH_USART_GPIO_CLK (RCC_APB2Periph_GPIOC)
#define BLUETOOTH_USART_GPIO_APBxClkCmd RCC_APB2PeriphClockCmd
#define BLUETOOTH_USART_TX_GPIO_PORT GPIOC
#define BLUETOOTH_USART_TX_GPIO_PIN GPIO_Pin_10
#define BLUETOOTH_USART_RX_GPIO_PORT GPIOC
#define BLUETOOTH_USART_RX_GPIO_PIN GPIO_Pin_11
#define BLUETOOTH_USART_IRQ USART3_IRQn
#define BLUETOOTH_USART_IRQHandler USART3_IRQHandler
void DEBUG_USART_Init(void);
void BLUETOOTH_USART_Init(void);
void LIDAR_USART_Init(void);
void Usart_SendByte(uint8_t Byte);
void Usart_SendArray(uint8_t *Array, uint16_t Length);
void Usart_SendPacket(void);
uint8_t Usart_GetRxFlag(void);
void BLUETOOTH_USART_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(BLUETOOTH_USART_GPIO_CLK, ENABLE);
RCC_APB1PeriphClockCmd(BLUETOOTH_USART_CLK, ENABLE);
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
GPIO_InitStructure.GPIO_Pin = BLUETOOTH_USART_TX_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(BLUETOOTH_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = BLUETOOTH_USART_RX_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(BLUETOOTH_USART_RX_GPIO_PORT, &GPIO_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = BLUETOOTH_USART_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_InitStructure.USART_BaudRate = BLUETOOTH_USART_BAUDRATE;
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;
USART_Init(BLUETOOTH_USARTx, &USART_InitStructure);
USART_ITConfig(BLUETOOTH_USARTx, USART_IT_RXNE, ENABLE);
USART_Cmd(BLUETOOTH_USARTx, ENABLE);
}
————————————————————————————————————————————————
关于重映射问题,这篇博客比较详细:
https://blog.youkuaiyun.com/a2001444/article/details/118049006