野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17141|回复: 1

关于串口3:无法使用,求高手指点!!

[复制链接]
发表于 2014-7-21 16:38:59 | 显示全部楼层 |阅读模式
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
       
        /* config USART1 clock */
        //RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2 | RCC_APB2Periph_GPIOA, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//
        /* USART1 GPIO config */
        /* Configure USART1 Tx (PA.09) as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOC, &GPIO_InitStructure);    //
        /* Configure USART1 Rx (PA.10) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOC, &GPIO_InitStructure);//
       
        /* USART1 mode config */
        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(USART3, &USART_InitStructure);//
       
        /* ê1Äü′®¿ú1½óêÕÖD¶Ï */
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//
       
        USART_Cmd(USART3, ENABLE);//
}

/// ÅäÖÃUSART1½óêÕÖD¶Ï
void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        /* Configure the NVIC Preemption Priority Bits */  
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
       
        /* Enable the USARTy Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;         //
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}


/// Öض¨Ïòc¿aoˉêyprintfμ½USART1
int fputc(int ch, FILE *f)
{
                /* ·¢Ëíò»¸ö×Ö½úêy¾Yμ½USART1 */
                USART_SendData(USART3, (uint8_t) ch);//
               
                /* μè′y·¢Ëííê±Ï */
                while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);                //
       
                return (ch);
}

/// Öض¨Ïòc¿aoˉêyscanfμ½USART1
int fgetc(FILE *f)
{
                /* μè′y′®¿ú1êäèëêy¾Y */
                while (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);//

                return (int)USART_ReceiveData(USART3);//
}

回复

使用道具 举报

发表于 2014-7-21 16:40:20 | 显示全部楼层
你先看看板子上的外设有没有用到usart3的引脚,把共用引脚的跳帽拔掉
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-9-22 09:47 , Processed in 0.027557 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表