GD32F130X USART2不能用

[复制链接]
2283|3
 楼主| molave20a 发表于 2015-2-14 16:42 | 显示全部楼层 |阅读模式
拿到一块GD32F130G8U6的板子,USART1没啥问题,USART2(PA8 TX,PB0 RX)死活不能用。用IAR调试的,设备选的STM32F100C8,HSE_STARTUP_TIMEOUT改成了0XFFFF。
求助!!

=================================================================
        RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA , ENABLE );
        RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB , ENABLE );

        RCC_APB2PeriphClockCmd( RCC_APB1Periph_USART2 , ENABLE );
        GPIO_DeInit( GPIOA );
        GPIO_DeInit( GPIOB );
        {
                /* Configure the GPIO ports */
                GPIO_InitTypeDef GPIO_InitStructure;
                /* Connect pin to Periph */
                GPIO_PinAFConfig( GPIOA , GPIO_PinSource8, GPIO_AF_4 );   
                GPIO_PinAFConfig( GPIOB , GPIO_PinSource0, GPIO_AF_4 );
               
                /* Configure pins as AF pushpull */
                GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_8;
                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_NOPULL;
                GPIO_Init( GPIOA , &GPIO_InitStructure);

                /* Configure pins as AF pushpull */
                GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_0;
                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_NOPULL;
                GPIO_Init( GPIOB , &GPIO_InitStructure);

               
        }

        {
          USART_InitTypeDef USART_InitStructure;
         
          USART_DeInit( USART2);

          USART_InitStructure.USART_BaudRate                         = 115200;
          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 enable */
        USART_Cmd(USART2, ENABLE);
        printf("abc");

=================================================================
sunmeat 发表于 2015-2-14 21:50 | 显示全部楼层
  1.        RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA , ENABLE );
  2.         RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB , ENABLE );

  3.         RCC_APB2PeriphClockCmd( RCC_APB1Periph_USART2 , ENABLE );

GPIO应该是挂在APB2的时钟上面,USART应该是挂在APB1的时钟上面了吧。
sunmeat 发表于 2015-2-14 21:50 | 显示全部楼层
以上代码是基于MDK中的分析,IAR没有试过。
 楼主| molave20a 发表于 2015-2-20 01:09 | 显示全部楼层
sunmeat 发表于 2015-2-14 21:50
GPIO应该是挂在APB2的时钟上面,USART应该是挂在APB1的时钟上面了吧。

的确是这个问题。折腾了一下午。谢谢哈
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

7

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部