USART1的RTS引脚和CAN的TX引脚复用,需要使用AFIO重新映射。
具体操作可以看下面的英文解释。
USART1_RTS and CAN_TX
Conditions
● USART1 is clocked
● CAN is not clocked
● I/O port pin PA12 is configured as an alternate functionoutput.
Description
Even if CAN_TX is not used, this signal is set by default to 1 ifI/O port pin PA12 is
configured as an alternate function output.
In this case USART1_RTS cannot be used.
Workaround
When USART1_RTS is used, the CAN must be remapped to eitheranoth
When USART1_RTS is used, the CAN must be remapped to either anotherIO configuration
when the CAN is used, or to the unused configuration(CAN_REMAP[1:0] set to “01”) when
the CAN is not used.//其他配置都和普通的一样,串口加上这句,添加流控
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
//复用
AFIO->MAPR=(AFIO->MAPR|AFIO_MAPR_CAN_REMAP_0|AFIO_MAPR_CAN_REMAP_1)&AFIO_MAPR_CAN_REMAP_0;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
|