我在配置stm32 串口1的时候,感觉自己的流程没有问题,但是发送的数据一直是 00
找了个demo 对比了下,也没发现什么问题, 一下配置代码 上面注释部分是demo的,测试ok, 下面是我的配置流程,感觉一个样啊,
怎么就不行了呢,大神求解答!!!
- void uart_init(void)
- {/*
- //GPIO????
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //??GPIOA??
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//??USART1??
-
- //??1????????
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9???USART1
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10???USART1
-
- //USART1????
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; //GPIOA9?GPIOA10
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//????
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //??50MHz
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //??????
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //??
- GPIO_Init(GPIOA,&GPIO_InitStructure); //???PA9,PA10
- //USART1 ?????
- USART_InitStructure.USART_BaudRate = 9600;//?????
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;//???8?????
- 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); //?????1
-
- USART_Cmd(USART1, ENABLE); //????1
-
- USART_ClearFlag(USART1, USART_FLAG_TC);
-
- */
-
- //1. gpio_clock on
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- //2. periph clock on
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
-
-
- //3. gpio_pinAfConfig
- GPIO_PinAFConfig(GPIOA, GPIO_Pin_9, GPIO_AF_USART1);
- GPIO_PinAFConfig(GPIOA, GPIO_Pin_10, GPIO_AF_USART1);
-
- // 4. gpio init
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- //5. uart init
- USART_InitTypeDef USART_InitStructure;
- USART_InitStructure.USART_BaudRate = 9600;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_Init(USART1, &USART_InitStructure);
-
- //6. uart enable
- //USART_ClearFlag(USART1, USART_FLAG_TC);
- USART_Cmd(USART1, ENABLE);
-
-
- }
复制代码
|
评分
查看全部评分