UART1不能发送数据

2019-03-23 20:17发布



我像发个数据05到串口上,函数如下,但是串口上显示不出来,请问下这是什么问题?

#include"stm32f10x.h"
 GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef  USART_InitStructure;
 

 int  main() {
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_USART1,ENABLE);
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;         //TX GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;    //RX GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure);
  // USART_StructInit(&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_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;               USART_Init(USART1,&USART_InitStructure);
                USART_Cmd(USART1, ENABLE);
//   USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);      //     USART_ITConfig(USART1, USART_IT_TXE, ENABLE);   USART_SendData(USART1, 0x05);


另外,如果调用了函数
USART_StructInit(&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_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;               USART_Init(USART1,&USART_InitStructure);
因为USART_StructInit(&USART_InitStructure);就是配置各成员的缺省值。
请大家指点指点!谢谢!
[ 本帖最后由 vipczx 于 2011-9-18 16:38 编辑 ] 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。