大学生
最后登录1970-1-1
在线时间 小时
注册时间2016-1-27
|
求助!为什么我用串口助手发送一个数据后,程序会停住,不运行了。不知道哪里处理出了问题。一共开了两中断,一个定时器6一个USART1接收中断,一开始定时器中断可以进去,当我用串口助手发送一个数据后,程序就停住了!附初始化和中断函数代码!
void User_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = BASE_TIM_IRQn;//定时器中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_USART_IRQ;//串口中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void Base_Timer6_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(BASE_TIM_CLK, ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler=8400-1;
TIM_TimeBaseStructure.TIM_Period = 1000-1;
TIM_TimeBaseInit(BASE_TIMER, &TIM_TimeBaseStructure);
TIM_ClearFlag(BASE_TIMER, TIM_FLAG_Update);
TIM_ITConfig(BASE_TIMER,TIM_IT_Update,ENABLE);
TIM_Cmd(BASE_TIMER, ENABLE);
}
void Debug_USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd( DEBUG_USART_RX_GPIO_CLK|DEBUG_USART_TX_GPIO_CLK, ENABLE);
RCC_APB2PeriphClockCmd(DEBUG_USART_CLK, ENABLE);
GPIO_PinAFConfig(DEBUG_USART_RX_GPIO_PORT,DEBUG_USART_RX_SOURCE, DEBUG_USART_RX_AF);
GPIO_PinAFConfig(DEBUG_USART_TX_GPIO_PORT,DEBUG_USART_TX_SOURCE,DEBUG_USART_TX_AF);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = DEBUG_USART_TX_PIN ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(DEBUG_USART_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = DEBUG_USART_RX_PIN;
GPIO_Init(DEBUG_USART_RX_GPIO_PORT, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = DEBUG_USART_BAUDRATE;
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(DEBUG_USART, &USART_InitStructure);
USART_ITConfig(DEBUG_USART, USART_IT_RXNE, ENABLE);
USART_Cmd(DEBUG_USART, ENABLE);
}
一下两个是中断函数
void BASE_TIM6_IRQHandler(void)
{
static unsigned int count1s=0,count100ms=0;
if(TIM_GetITStatus(BASE_TIMER,TIM_IT_Update)!=RESET)
{
//Time_Flag=1;
//GPIO_ToggleBits (XUANTONG_GPIO,CESHI_GPIO_PIN);
count1s++;
count100ms++;
TIM_ClearITPendingBit(BASE_TIMER,TIM_IT_Update);
}
if(count1s>=2)
{
count1s=0;
Time_Flag=1;
Chan_Chose_Time=1;
}
}
void DEBUG_USART_IRQHandler(void)
{
if(USART_GetITStatus( DEBUG_USART, USART_IT_RXNE ) != RESET)
{
Rxflag=1;
ucTemp = USART_ReceiveData( DEBUG_USART );
USART_ClearITPendingBit (DEBUG_USART,USART_IT_RXNE);
}
}
主函数:
int main(void)
{
User_NVIC_Configuration();
Time6_Init();
Debug_USART_Config();
//Rheostat_Init();
User_Gpio_Init();
while(1)
{
if(Rxflag==1)
{
printf("\r\n %c \r\n",ucTemp);
}
if(Time_Flag==1)
{
Time_Flag=0;
GPIO_ToggleBits(LED_GPIO,LEDR_GPIO_PIN|LEDB_GPIO_PIN|LEDG_GPIO_PIN);
}
}
}
是中断的嵌套问题还是别的什么?我把抢占优先级和子优先级设置为相同时,一样的问题。
|
|