野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7432|回复: 2

stm32 UART5接的GPS, 直接打印USART_ReceiveData(UART5)收到的数据为0, 中断函...

[复制链接]
发表于 2016-10-11 20:20:57 | 显示全部楼层 |阅读模式
stm32  UART5接的GPS, 直接打印USART_ReceiveData(UART5)收到的数据为0, 中断函数也进不去,  有遇到这种情况的吗?




unsigned char TxBuffer5[100] ;
unsigned int i;
unsigned int flag;


void RCC_Configuration()
{
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO
                                                        |RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);

}


void NVIC_Configuration( )
{
        NVIC_InitTypeDef NVIC_InitStructure;

        NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}


void GPIO_Configuration()
{
        GPIO_InitTypeDef GPIO_InitStructure;

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init( LED_RED_GPIO, &GPIO_InitStructure);
        GPIO_SetBits( GPIOC, GPIO_Pin_7);
       
        //--------UART5 TX  AF_PP---------------------//
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
        GPIO_Init(GPIOD,&GPIO_InitStructure);

        //--------UART5 RX IN_FLOATING---------------------//
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOC,&GPIO_InitStructure);
}


void UART5_Configuration( )
{
        USART_InitTypeDef USART_InitStructure;

        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(UART5, &USART_InitStructure);
        USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
        USART_Cmd(UART5, ENABLE);

}



void UART5_IRQHandler(void)
{
       
        printf("aaaaa");
        if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
        {
                TxBuffer5[i]=USART_ReceiveData(UART5);
                i++;
        }       
        if(i==50)
        {       
                flag=1;
                i=0;
        }
       
}





int main()
{

        Usart1_Init();
        RCC_Configuration();
        GPIO_Configuration();
        NVIC_Configuration( );
        UART5_Configuration();

        while(1)
        {
               
                i = USART_ReceiveData(UART5);
               
                printf("%x,", i);
               
                if(flag)
                {
                        for(i = 0; i<50; i++)
                        {
                                printf("%x, ", TxBuffer5[i]);
                        }
                        flag=0;       
                }       
        }
}


回复

使用道具 举报

 楼主| 发表于 2016-10-11 20:23:19 | 显示全部楼层
GPS模块电源控制脚,高电平打开电源------->上面代码的PC7,   UART5的波特率9600  115200也都试过了不行,
回复 支持 反对

使用道具 举报

发表于 2016-10-12 10:37:37 | 显示全部楼层
用配套的例程试过没呢?
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-1 09:31 , Processed in 0.033249 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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