|

楼主 |
发表于 2016-10-15 08:43:45
|
显示全部楼层
回 shuaigew88 的帖子
shuaigew88:
只要在设计版图时端口没有被其他硬件占用或冲突一般都不会有问题,既然你说不能用那么有几点可能。
1:GPIOC口有无正确配置为USART6?
2:GPIOC端口时钟是否使能? 
1:GPIOC口有正确配置为USART6
2:GPIOC端口时钟使能了。
另外,为了防止干扰,我把其余程序全部删除,整个工程只有USART6的程序代码,结果只要USART6映射到PC6,PC7,通信就不通,但是映射到PG14,PG9通信就OK。
为什么USART6映射到PC6,PC7,通信就不通呢?而映射到PG14,PG9通信就OK呢?
USART6映射到PC6,PC7初始化程序如下:
void USART6_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); //for USART1 and USART6
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); // GPIOC时钟使能
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); // GPIOC6
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6); // GPIOC7
// Configure USART6 Tx (PC.06) as alternate function push-pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;// GPIOC6
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure); // GPIOC6
// Configure USART6 Rx (PC.07) as input floating
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; // GPIOC7
GPIO_Init(GPIOC, &GPIO_InitStructure); // GPIOC7
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;
USART_Init(USART6, &USART_InitStructure);
USART_Cmd(USART6, ENABLE);
//CPU的小缺陷:串口配置好,如果直接Send,则第1个字节发送不出去如下语句解决第1个字节无法正确发送出去的问题
USART_ClearFlag(USART6, USART_FLAG_TC); //清发送完成标志,Transmission Complete flag
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);
} |
|