中级会员
 
- 积分
- 451
- 金钱
- 451
- 注册时间
- 2017-2-1
- 在线时间
- 74 小时
|
10金钱
由于两个设备共用了串口1,使用时映射到不同的引脚区分不同的设备。现在遇到的问题是,第一次重映射使用正常,然后转到另一个设备时却无法发送数据。有大神知道这是什么原因吗?第一次初始化代码如下:
RCC_APB2PeriphClockCmd(GSM_COM1_TX_GPIO_CLK | GSM_COM1_RX_GPIO_CLK, ENABLE);
/* Enable UART clock */
RCC_APB2PeriphClockCmd(GSM_COM1_CLK, ENABLE);
//打开外设利用时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
//打开串口重映射时钟
GPIO_PinRemapConfig(GSM_COM1_GPIO_REMAP, ENABLE);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = GSM_COM1_RX_PIN;
GPIO_Init(GSM_COM1_RX_GPIO_PORT, &GPIO_InitStructure);
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GSM_COM1_TX_PIN;
GPIO_Init(GSM_COM1_TX_GPIO_PORT, &GPIO_InitStructure);
/* USART configuration */
USART_Init(GSM_COM1_PORT, USART_InitStruct);
/* Enable USART Receive and Transmit interrupts */
USART_ITConfig(GSM_COM1_PORT, USART_IT_RXNE, ENABLE);
/* Enable USART */
USART_Cmd(GSM_COM1_PORT, ENABLE);
第二次初始化代码如下:
RCC_APB2PeriphClockCmd(ORB_COM1_TX_GPIO_CLK | ORB_COM1_RX_GPIO_CLK, ENABLE);
/* Enable UART clock */
RCC_APB2PeriphClockCmd(ORB_COM1_CLK, ENABLE);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = ORB_COM1_RX_PIN;
GPIO_Init(ORB_COM1_RX_GPIO_PORT, &GPIO_InitStructure);
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = ORB_COM1_TX_PIN;
GPIO_Init(ORB_COM1_TX_GPIO_PORT, &GPIO_InitStructure);
/* USART configuration */
USART_Init(ORB_COM1_PORT, USART_InitStruct);
单独使用任何一个初始化都没有问题,所以排除引脚时钟等基本配置的错误。
|
最佳答案
查看完整内容[请看2#楼]
问题解决。需要这个函数GPIO_PinRemapConfig(GPIO_Remap_USART1,DISABLE);把串口的重映射关掉。
|