基本GPIO及USART3配置如下(PC10,PC11),主函数基本没啥东西,就简单发送个0x11,时钟、IO模式、USART时钟及配置,都没有问题了,请问大家到底还差到哪,哪里被我忘掉了?
void USART_GPIO_ConFig(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //USART3 GPIO RCC Enable
/* Connect PXx to USARTx_Tx*/
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
/* Connect PXx to USARTx_Rx*/
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_PinSource10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure USART Rx as alternate function */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_PinSource11;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* USART configuration */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //USART3 RCC Enable
USART_InitStructure.USART_BaudRate = 115200;
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(USART3, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART3, ENABLE);
}
int main()
{
int i;
USART_GPIO_ConFig();
// printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
while(1)
{
USART_SendData(USART3, 0x11);
for(i=0;i<1000;i++)
{
}
}
return 0;
} |