之前发有一贴查找问题,现在出问题的地方找到了,但是看不出是哪里错了。。
采用SIM928A模块(GSM/GPS二合一模块),串口5是接收GPS数据,串口6是GSM数据,问题就在于同时用的时候代码会跑死,把其中一块的代码注释掉,整个程序就没问题。
当程序跑死的时候,程序中的中断还是正常的,就是程序主循环不跑,从这里判断是程序在某个循环里出不来了,,当程序挂的时候停止调试,根据LR指针地址和.map文件,确定是
最后的LR指针停在uart5里,并且是在串口5中断程序的判定中断标志位这个函数里。也搞不明白为什么在这个函数里出不来,这函数也没有循环啊。
我贴下代码,求帮忙看看!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#include "usart6.h"
#include "stdarg.h"
#include "stdio.h"
#include "string.h"
#include "timer.h"
//′®¿ú·¢Ëí»o′æÇø
__align(8) u8 USART6_TX_BUF[USART6_MAX_SEND_LEN]; //·¢Ëí»o3å,×î′óUSART3_MAX_SEND_LEN×Ö½ú
//′®¿ú½óêÕ»o′æÇø
u8 USART6_RX_BUF[USART6_MAX_RECV_LEN]; //½óêÕ»o3å,×î′óUSART3_MAX_RECV_LEN¸ö×Ö½ú.
//í¨1yÅD¶Ï½óêÕá¬Dø2¸ö×Ö·ûÖ®¼äμÄê±¼ä2î2»′óóú100msà′¾ö¶¨êÇ2»êÇò»′Îá¬DøμÄêy¾Y.
//èç1û2¸ö×Ö·û½óêÕ¼ä¸ô3¬1y100ms,ÔòèÏÎa2»êÇ1′Îá¬Døêy¾Y.ò2¾íêÇ3¬1y100msûóD½óêÕμ½
//èÎoÎêy¾Y,Ôò±íê¾′Ë′νóêÕíê±Ï.
//½óêÕμ½μÄêy¾Y×′ì¬
//[15]:0,ûóD½óêÕμ½êy¾Y;1,½óêÕμ½áËò»Åúêy¾Y.
//[14:0]:½óêÕμ½μÄêy¾Y3¤¶è
u16 USART6_RX_STA=0;
void USART6_IRQHandler(void)//GSM
{
u8 res;
if(USART_GetITStatus(USART6, USART_IT_RXNE) != RESET)//½óêÕμ½êy¾Y
{
res =USART_ReceiveData(USART6);
if((USART6_RX_STA&(1<<15))==0)//½óêÕíêμÄò»Åúêy¾Y,»1ûóD±»′|àí,Ôò2»Ôù½óêÕÆäËûêy¾Y
{
if(USART6_RX_STA<USART6_MAX_RECV_LEN) //»1¿éòÔ½óêÕêy¾Y
{
TIM_SetCounter(TIM5,0);//¼ÆêyÆ÷Çå¿Õ
if(USART6_RX_STA==0)
TIM_Cmd(TIM5, ENABLE); //ê1Äü¶¨ê±Æ÷5
USART6_RX_BUF[USART6_RX_STA++]=res; //¼Ç¼½óêÕμ½μÄÖμ
}
else
{
USART6_RX_STA|=1<<15; //Ç¿ÖƱê¼Ç½óêÕíê3é
}
}
USART_ClearITPendingBit(USART6, USART_IT_RXNE);
}
USART_SendData(USART1, (uint8_t) res);
/* μè′y·¢Ëí½áêø */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
}
//3õê¼»ˉIO ′®¿ú6
//bound:2¨ìØÂê
void usart6_init(u32 bound)
{
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource9, GPIO_AF_USART6);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource14, GPIO_AF_USART6);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_14;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_SetBits(GPIOG,GPIO_Pin_0); //à-¸ß
USART_InitStructure.USART_BaudRate = bound;
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(USART6, &USART_InitStructure);
/* Enable USART */
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);
USART_Cmd(USART6, ENABLE);
USART_ClearFlag(USART6, USART_FLAG_TC);
TIM5_Int_Init(1000-1,840-1); //10msÖD¶Ï
TIM_Cmd(TIM5, DISABLE); //1رն¨ê±Æ÷5
}
void Gsm_Gps_Start(void)
{
GSM_PWR = 0;
delay_ms(2000);
GSM_PWR = 1;
}
//′®¿ú6,printf oˉêy
//è·±£ò»′η¢Ëíêy¾Y2»3¬1yUSART6_MAX_SEND_LEN×Ö½ú
void u6_printf(char* fmt,...)
{
u16 i,j;
va_list ap;
va_start(ap,fmt);
vsprintf((char*)USART6_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART6_TX_BUF);//′Ë′η¢Ëíêy¾YμÄ3¤¶è
for(j=0;j<i;j++)//Ñ-»··¢Ëíêy¾Y
{
while(USART_GetFlagStatus(USART6,USART_FLAG_TC)==RESET); //μè′yéÏ′Î′«êäíê3é
USART_SendData(USART6,(uint8_t)USART6_TX_BUF[j]); //·¢Ëíêy¾Yμ½′®¿ú3
}
}
[/mw_shl_code]
#include "stdarg.h"
#include "stdio.h"
#include "string.h"
#include "timer.h"
//′®¿ú·¢Ëí»o′æÇø
u8 USART5_TX_BUF[USART5_MAX_SEND_LEN]; //·¢Ëí»o3å,×î′óUSART3_MAX_SEND_LEN×Ö½ú
//′®¿ú½óêÕ»o′æÇø
u8 USART5_RX_BUF[USART5_MAX_RECV_LEN]; //½óêÕ»o3å,×î′óUSART3_MAX_RECV_LEN¸ö×Ö½ú.
//extern unsigned char gpsData[512];
//í¨1yÅD¶Ï½óêÕá¬Dø2¸ö×Ö·ûÖ®¼äμÄê±¼ä2î2»′óóú100msà′¾ö¶¨êÇ2»êÇò»′Îá¬DøμÄêy¾Y.
//èç1û2¸ö×Ö·û½óêÕ¼ä¸ô3¬1y100ms,ÔòèÏÎa2»êÇ1′Îá¬Døêy¾Y.ò2¾íêÇ3¬1y100msûóD½óêÕμ½
//èÎoÎêy¾Y,Ôò±íê¾′Ë′νóêÕíê±Ï.
//½óêÕμ½μÄêy¾Y×′ì¬
//[15]:0,ûóD½óêÕμ½êy¾Y;1,½óêÕμ½áËò»Åúêy¾Y.
//[14:0]:½óêÕμ½μÄêy¾Y3¤¶è
u16 USART5_RX_STA=0;
void uart5_init(u32 bound)
{
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// USART_ClockInitTypeDef USART_ClockInitStructure;
/* Enable the USARTx Interrupt */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOC,ENABLE); //ê1ÄüGPIODê±Öó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);//ê1ÄüUSART3ê±Öó
USART_DeInit(UART5); //¸′λ′®¿ú3
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;//GPS
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
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);
/* Enable USART */
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_Cmd(UART5, ENABLE);
USART_ClearFlag(UART5, USART_FLAG_TC);
}
void UART5_IRQHandler(void)//GPS
{
u8 res;
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)//½óêÕμ½êy¾Y
{
res =USART_ReceiveData(UART5);
if((USART5_RX_STA&(1<<15))==0)//½óêÕíêμÄò»Åúêy¾Y,»1ûóD±»′|àí,Ôò2»Ôù½óêÕÆäËûêy¾Y
{
if(USART5_RX_STA<USART5_MAX_RECV_LEN) //»1¿éòÔ½óêÕêy¾Y
{
USART5_RX_BUF[USART5_RX_STA++]=res; //¼Ç¼½óêÕμ½μÄÖμ
}
else
{
USART5_RX_STA|=1<<15; //Ç¿ÖƱê¼Ç½óêÕíê3é
}
}
USART_ClearITPendingBit(UART5, USART_IT_RXNE);
}
}
int u5_receive_data(char* data)
{
unsigned short rxlen=0;
//data[0]=0;
if(USART5_RX_STA&0X8000)
{
rxlen=USART5_RX_STA&0X7FFF; //μÃμ½êy¾Y3¤¶è
USART5_RX_BUF[rxlen]=0;
memcpy(data,USART5_RX_BUF,strlen((char*)USART5_RX_BUF));
USART5_RX_STA=0; //Æô¶ˉÏÂò»′νóêÕ
return rxlen;
}
return 0;
}
void u5_printf(char* fmt,...)
{
u16 i,j;
va_list ap;
va_start(ap,fmt);
vsprintf((char*)USART5_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART5_TX_BUF);//′Ë′η¢Ëíêy¾YμÄ3¤¶è
for(j=0;j<i;j++)//Ñ-»··¢Ëíêy¾Y
{
while(USART_GetFlagStatus(UART5,USART_FLAG_TC)==RESET); //μè′yéÏ′Î′«êäíê3é
USART_SendData(UART5,(uint8_t)USART5_TX_BUF[j]); //·¢Ëíêy¾Yμ½′®¿ú3
}
}
[/mw_shl_code]
一周热门 更多>