首页 新闻 会员 周边

STM32 F401系列串口问题咨询

0
悬赏园豆:50 [待解决问题]

如下代码的一段串口的调试代码,我已经按照usart文件的最简要求去写了,但是现在无法实现串口通信,串口上面的RX灯始终是亮着的,已经确定和电脑相连的串口小板是正常的,开发板也是没有硬件问题的。

void Usart_init_for_lsm303(void)

{

    USART_InitTypeDef USART_InitStructure;   

    GPIO_InitTypeDef GPIO_InitStructure;

    /* config USART2 clock */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);

   // USART_DeInit(USART2);

 

   GPIO_PinAFConfig(GPIOD,GPIO_Pin_5,GPIO_AF_USART2);

   GPIO_PinAFConfig(GPIOD,GPIO_Pin_6,GPIO_AF_USART2);

 

    /*USART2 GPIO config*/

    /* Configure USART2 Tx (PD.05) as alternate function push-pull */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//推挽输出这里的pupd应该使用什么?

    GPIO_Init(GPIOD, &GPIO_InitStructure);    

    /* Configure USART2 Rx (PD.06) as input floating */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//float in这里应该使用什么?

    GPIO_Init(GPIOD, &GPIO_InitStructure);

 

    /*USART2 mode config*/

    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(USART2, &USART_InitStructure);

    USART_Cmd(USART2,ENABLE);

}

再main函数里面做循环发送数据和亮灯的操作:

  while (1)

  {

      STM_EVAL_LEDOn(LED3);

      delay_ms(1000);

      USART_SendData(USART2,19);

      STM_EVAL_LEDOff(LED3);

      delay_ms(1000);

      USART_SendData(USART2,0);

  }

大敏Sensor的主页 大敏Sensor | 初学一级 | 园豆:152
提问于:2014-06-04 16:28
< >
分享
所有回答(1)
0

看看这个

http://www.360doc.com/content/12/0413/11/9428311_203244457.shtml

LiuKaiFa | 园豆:1491 (小虾三级) | 2014-06-04 21:37

这个应该不行   

支持(0) 反对(0) 大敏Sensor | 园豆:152 (初学一级) | 2014-06-05 09:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册