打印

新手求助

[复制链接]
165|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Spikess|  楼主 | 2018-7-29 15:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
按教程自己为串口3通信,为啥不能通信,求高手解答
void My_USART3_Init()
{
        GPIO_InitTypeDef GPIO_InitStruct;
        USART_InitTypeDef USART_InitStruct;
        NVIC_InitTypeDef NVIC_InitStruct;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
        
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
        GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
        GPIO_InitStruct.GPIO_Pin= GPIO_Pin_8;
        GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStruct.GPIO_PuPd= GPIO_PuPd_UP;
        GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;
    GPIO_Init(GPIOD, &GPIO_InitStruct);
        
        GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
        GPIO_InitStruct.GPIO_Pin= GPIO_Pin_9;
        GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
        GPIO_InitStruct.GPIO_PuPd= GPIO_PuPd_UP;
        GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;
    GPIO_Init(GPIOD, &GPIO_InitStruct);
        
        USART_InitStruct.USART_BaudRate=115200;
        USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
        USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
        USART_InitStruct.USART_Parity=USART_Parity_No;
        USART_InitStruct.USART_StopBits=USART_StopBits_1;
        USART_InitStruct.USART_WordLength=USART_WordLength_8b;
        USART_Init(USART3, &USART_InitStruct);
    USART_Cmd(USART3,ENABLE);
        USART_ITConfig(USART3,USART_IT_RXNE,ENABLE)
        ;        
        NVIC_InitStruct.NVIC_IRQChannel=USART3_IRQn;
        NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
        NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;
        NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;
        NVIC_Init(&NVIC_InitStruct);
}
void USART3_IRQHandler()
{
        u8 res;
        if(USART_GetITStatus(USART3,USART_IT_RXNE))
        {
                                
                res=USART_ReceiveData(USART3);
                USART_SendData(USART3,res);
        }
}

使用特权

评论回复

相关帖子

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

本版积分规则

417

主题

421

帖子

0

粉丝