cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with set priority in STM32F429ZI.

hukhongcongtu26111993
Associate II
Posted on May 31, 2016 at 11:02

#include <
main.h
>
#define Led_Green GPIO_Pin_13
#define Led_Red GPIO_Pin_14
void LED_Config(void)
{
GPIO_InitTypeDef GPIO_Init_Var={0};
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
GPIO_Init_Var.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14; 
GPIO_Init_Var.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init_Var.GPIO_OType = GPIO_OType_PP;
GPIO_Init_Var.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init_Var.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOG, &GPIO_Init_Var); 
}
void ****_Config(void)
{
GPIO_InitTypeDef GPIO_Init_Var={0};
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_Init_Var.GPIO_Pin = GPIO_Pin_0; 
GPIO_Init_Var.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init_Var.GPIO_OType = GPIO_OType_PP;
GPIO_Init_Var.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init_Var.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_Init_Var); 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_Init_Var.GPIO_Pin = GPIO_Pin_1; 
GPIO_Init_Var.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init_Var.GPIO_OType = GPIO_OType_PP;
GPIO_Init_Var.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init_Var.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &GPIO_Init_Var);
}
void EXTILine0_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_SetPriority(EXTI_Line0,1);
}
void EXTILine1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOB, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_SetPriority(EXTI_Line1,0);
}
int main(void)
{
LED_Config();
****_Config();
EXTILine0_Config();
EXTILine1_Config();
while(1)
{
GPIO_SetBits(GPIOG,Led_Green|Led_Red);
}
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{ 
EXTI_ClearITPendingBit(EXTI_Line0);
GPIO_ResetBits(GPIOG,Led_Green);
Delay_ms(10000);
USART_Send_Variable(USART1,dem0); 
}
}
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line1);
GPIO_ResetBits(GPIOG,Led_Red);
Delay_ms(10000); 
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{ 
while (1)
{
}
}
#endif
///*________________________________________MADE_BY_NEDU________________________________________*/
I want to turn on 2 LED on while(1) loop, if I press button 0, Led_Green is on. then I press button 1, LED_Red is onimmediately. Butreality isincorrect.if I press button 0,Led_Green is on,I press button 1,affter 10second, LED_Red will on. seem,priority neverestablish. anyone help me please!!!!

1 REPLY 1
Posted on May 31, 2016 at 13:26

You define NVIC Group settings somewhere?

Millisecond delay is a achieved how?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..