打印

GD32F130X USART2不能用

[复制链接]
1915|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 | 只看该作者
       RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA , ENABLE );
        RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB , ENABLE );

        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

粉丝