USART数据发送问题

2019-07-20 15:37发布

void USART_Init_Test(void)
{
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);

        GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
        GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);

        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;       
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        GPIO_Init(GPIOA,&GPIO_InitStructure);

        USART_InitTypeDef USART_InitStructure;
        USART_InitStructure.USART_BaudRate = 9600;
        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(USART1, &USART_InitStructure);

        USART_Cmd(USART1,ENABLE);       
}
int main(void)
{
        USART_Init_Test();
        u8 a=0x66;
        while(1)
        {
                USART_SendData(USART1,a);
                delay_ms(500);
        }
        return 1;
}
上述代码,加入了delay之后串口助手就只能收到一次数据,按复位之后就又能再次收到一个数据;
删除delay_ms(500);后,串口调试助手就会一直收到数据;

为什么加入delay之后,串口调试助手上无法产生每隔500ms就收到单片机发来一条数据的现象呢?

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