打印

GD32D130的USART2问题

[复制链接]
920|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
kangwenhong1992|  楼主 | 2015-8-4 09:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我想知道我想知道USART2初始化设置的时候有什么特殊的设置吗?为什么我和USART1相同的设置可是USART的STR寄存器中的REA一直不置位,导致我一直不能接收。。。初始化程序如下:
void USART2_init(void)
{
                 NVIC_InitPara NVIC_InitStructure;
    /* Enable the USARTx Interrupt */
    NVIC_InitStructure.NVIC_IRQ = USART2_IRQn;                 //ÖжÏÀàÐÍ
    NVIC_InitStructure.NVIC_IRQPreemptPriority = 0;            //ÖжÏÓÅÏȼ¶
    NVIC_InitStructure.NVIC_IRQSubPriority = 0;                                                                //
    NVIC_InitStructure.NVIC_IRQEnable = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
       
    RCC_AHBPeriphClock_Enable( RCC_AHBPERIPH_GPIOA , ENABLE );            //ʹÄÜGPIOAʱÖÓ
    RCC_APB1PeriphClock_Enable( RCC_APB1PERIPH_USART2, ENABLE );                                        /* Enable USART1 APB clock */   
//    GPIO_DeInit( GPIOA );                                     //UART1        ÅäÖÃ
    {/*************** usart2 ¶Ë¿ÚÉèÖÃ*****************/
        GPIO_InitPara GPIO_InitStructure1;
        GPIO_PinAFConfig( GPIOA , GPIO_PINSOURCE2, GPIO_AF_1 );
        GPIO_PinAFConfig( GPIOA , GPIO_PINSOURCE3, GPIO_AF_1 );        /** usart1 **/
        GPIO_InitStructure1.GPIO_Pin = GPIO_PIN_2 | GPIO_PIN_3;
        GPIO_InitStructure1.GPIO_Mode = GPIO_MODE_AF;
        GPIO_InitStructure1.GPIO_Speed = GPIO_SPEED_50MHZ;
        GPIO_InitStructure1.GPIO_OType = GPIO_OTYPE_PP;
        GPIO_InitStructure1.GPIO_PuPd = GPIO_PUPD_NOPULL;
        GPIO_Init( GPIOA , &GPIO_InitStructure1);
    }
    {
        USART_InitPara USART_InitStructure;   
        USART_DeInit( USART2 );
        USART_InitStructure.USART_BRR = 115200;
        USART_InitStructure.USART_WL = USART_WL_8B;
        USART_InitStructure.USART_STBits = USART_STBITS_1;
        USART_InitStructure.USART_Parity = USART_PARITY_RESET;
        USART_InitStructure.USART_HardwareFlowControl = USART_HARDWAREFLOWCONTROL_NONE;      //Ó²¼þ¿ØÖÆÎÞ
        USART_InitStructure.USART_RxorTx = USART_RXORTX_RX | USART_RXORTX_TX;      
        USART_Init(USART2, &USART_InitStructure);
    }
    USART_Enable(USART2, ENABLE);  
}
沙发
dbayj| | 2015-8-4 12:23 | 只看该作者
你用的是130X4还是其他?引脚定义不一样的。

使用特权

评论回复
板凳
sunmeat| | 2015-8-7 08:17 | 只看该作者
楼主你解决了没有呢?可以参考官方的例程呀。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

12

帖子

0

粉丝