想直接32给上位机发送数据,不用中断,数据一直没有写入DR寄存器,在那里循环,怎么回事?在线等,挺急的!

2019-08-17 02:25发布

#include "stm32f10x.h"


void My_USART1_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStrue;
    USART_InitTypeDef USART_InitStrue;
//    NVIC_InitTypeDef NVIC_InitStrue;
   
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//使能GPIO时钟
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//使能串口时钟
//USART_TX PA.9
    GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;//推挽复用
    GPIO_InitStrue.GPIO_Pin=GPIO_Pin_9;
    GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
  GPIO_Init(GPIOA,&GPIO_InitStrue);//¢Ú
    //USART1_RX  PA.10 ¸¡¿ÕÊäÈë
    GPIO_InitStrue.GPIO_Mode=GPIO_Mode_IN_FLOATING;//¸浮空
    GPIO_InitStrue.GPIO_Pin=GPIO_Pin_10;
    GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
  GPIO_Init(GPIOA,&GPIO_InitStrue);//¢Ú
   
    USART_InitStrue.USART_BaudRate=115200;//设置波特率
    USART_InitStrue.USART_HardwareFlowControl=USART_HardwareFlowControl_None;//无硬件流数据
    USART_InitStrue.USART_Mode=USART_Mode_Tx;//设置为发送模式
    USART_InitStrue.USART_Parity=USART_Parity_No;//无奇偶校验位
    USART_InitStrue.USART_StopBits=USART_StopBits_1;//一个停止位
    USART_InitStrue.USART_WordLength=USART_WordLength_8b;//字长为8位
   
    USART_Init(USART1,&USART_InitStrue);//串口设置
   
    USART_Cmd(USART1,ENABLE);//使能串口

   
}

void delay(u32 k)
{
        u32 a,b;
     for(a=3000;a>0;a--)
                for(b=k;b>0;b--);
}
int main(void)
{   
     u8 i,j[]={1,2,3,4,5};
   
   //USART_DeInit(USART1);
    My_USART1_Init();
   
     while(1)
         {
                for(i=0;i<5;i++)
                {    USART_SendData(USART1,j[i]);
                    while(USART_GetFlagStatus(USART1, USART_FLAG_TC));
                    delay(2);
                }
         }
     
}


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