关于STM32F407的usart

2019-07-14 23:24发布

有谁能告诉我为什么我用了USART_SendData(),但是SART->DR寄存器中的值一直都是0,其他寄存器都有变化啊,就DR寄存器的值写不进去。
#include <STM32f4xx.h>
void GPIO_Configuration(void)
{
    GPIO_InitTypeDef    GPIO_InitStructure;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

    GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);

    //PD8(TX)设置成复用推挽输出
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

    //PD9(RX)设置成浮空输入
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOD, &GPIO_InitStructure);   
}
void USART_Configuration(void)
{
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
   USART_InitTypeDef    USART_InitStruct;
   USART_InitStruct.USART_BaudRate = 9600;
   USART_InitStruct.USART_WordLength = USART_WordLength_8b;
   USART_InitStruct.USART_StopBits = USART_StopBits_1;
   USART_InitStruct.USART_Parity = USART_Parity_No ;
   USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
   USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
   USART_Init(USART3,&USART_InitStruct);
   USART_Cmd(USART3,ENABLE);
}

void main()
{
u8 i;
    GPIO_Configuration();
    USART_Configuration();
    uint16_t  tab='A';
    for(i=0;i<17;i++)
    {
        USART_SendData(USART3,tab);
        tab++;
        while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);     
    }  
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。