main{ ..... Timer1Init();这里开了两个定时器中断 UartInit();这里开了三个串口中断 while(1); } 一开始只开一个定时器中断到时候,串口也开了三个中断,结果正常 后来,又增加了一个定时器中断,结果就死机了,但是如果取消串口中断,又正常了,搞不懂? 每一个子中断优先级都不一样,哪里出了问题?担心是抢占优先级、子优先级出了问题,这两个问题我不是很懂。 void Timer1Init (void) { // Set timer period 0.1 sec TIM1_TimeBaseInitStruct.TIM1_Prescaler = 720; // 10us resolution TIM1_TimeBaseInitStruct.TIM1_CounterMode = TIM1_CounterMode_Up; TIM1_TimeBaseInitStruct.TIM1_Period = 1000; // 10 ms TIM1_TimeBaseInitStruct.TIM1_ClockDivision = TIM1_CKD_DIV1; TIM1_TimeBaseInitStruct.TIM1_RepetitionCounter = 0; TIM1_TimeBaseInit(&TIM1_TimeBaseInitStruct);
// Clear update interrupt bit TIM1_ClearITPendingBit(TIM1_FLAG_Update); // Enable update interrupt TIM1_ITConfig(TIM1_FLAG_Update,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQChannel; //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); Timer3Init (); } void Timer3Init (void) { // Set timer period s sec TIM_TimeBaseStructure.TIM_Prescaler = 7200; // 100us resolution TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 10000;// 10000*0.1 ms=1s TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_UpdateDisableConfig(TIM3,DISABLE); TIM_ARRPreloadConfig(TIM3,ENABLE); //TIM_SelectOutputTrigger(TIM3,TIM_TRGOSource_Update); TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //允许TIM3更新事件中断 TIM_Cmd(TIM3, ENABLE);//开启TIM3
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel; //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void UartInit (void) { USART_InitStructure.USART_BaudRate = baudrate1; 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_InitStructure.USART_Clock = USART_Clock_Disable; USART_InitStructure.USART_CPOL = USART_CPOL_Low; USART_InitStructure.USART_CPHA = USART_CPHA_2Edge; USART_InitStructure.USART_LastBit = USART_LastBit_Disable; /* Configure USART1 --->GPS 9600*/ USART_Init(USART1, &USART_InitStructure); USART_InitStructure.USART_BaudRate = baudrate2; /* Configure USART2 --->pc 115200 */ USART_Init(USART2, &USART_InitStructure); USART_InitStructure.USART_BaudRate = baudrate3; /* Configure USART3 --->GSM 115200*/ USART_Init(USART3, &USART_InitStructure); // Enable USART1 Receive and Transmit interrupt USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //USART_ITConfig(USART1, USART_IT_TXE, ENABLE); USART_ITConfig(USART1, USART_IT_TC, ENABLE);
// Enable USART2 Receive and Transmit interrupt USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //USART_ITConfig(USART2, USART_IT_TXE, ENABLE); USART_ITConfig(USART2, USART_IT_TC, ENABLE); // Enable USART3 Receive and Transmit interrupt USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //USART_ITConfig(USART3, USART_IT_TXE, ENABLE); USART_ITConfig(USART3, USART_IT_TC, ENABLE); // // Configure the NVIC Preemption Priority Bits NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); // Enable the USART1 Interrupt NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 10; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
// Enable the USART2 Interrupt NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 11; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // Enable the USART3 Interrupt NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 12; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } |