学前班
最后登录1970-1-1
在线时间 小时
注册时间2016-10-11
|
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;
}
}
}
|
|