cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f429zi_interrupt_register init qusetion

Kang Sung Gu
Associate II
Posted on September 15, 2017 at 06:58

CUBE MX Basic Settings (STM32F429ZI)

and My code

.

.

.

int main(void)

{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */

  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */

  /* USER CODE BEGIN 2 */

 

  //GPIOG PIN 13,14 init

  __HAL_RCC_GPIOG_CLK_ENABLE(); //RCC GPIO Enable

  __HAL_RCC_GPIOA_CLK_ENABLE();

 

  GPIOA->PUPDR = 0x00000002; //GPIOA_PIN0 PULL DOWN  SET

 

  GPIOG->MODER = 0x04000000; //GPIOG_PIN_13 OUTPUT MODE

  GPIOG->OTYPER = 0x00000000; //GPIOG PORT Push-Pull

 GPIOG->OSPEEDR = 0x0C000000; //GPIOG_PIN_13 HIGH SPEED

  GPIOG->PUPDR =   0x00000000; //no pullup no pulldown

  //interrupt init

  __HAL_RCC_SYSCFG_CLK_ENABLE();

  SYSCFG->EXTICR[0] =0x00000000; //PA0 interrupt enable

  EXTI->IMR = 0x00000001; //EXTI 0 enable

  EXTI->RTSR = 0x00000001;//EXTI0 rising edge enable

 

  /* USER CODE END 2 */

  /* Infinite loop */

  /* USER CODE BEGIN WHILE */

  while (1)

  {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }

  /* USER CODE END 3 */

}

.

.

.

/* USER CODE BEGIN 4 */

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){

  if(GPIO_Pin == GPIO_PIN_0)  //rising edge in PA0

            HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_13);

  else

    __NOP();

}

register init good but it is not working....

It works fine if I set it to CUBE MX and run it

Circuit is When the button is pressed, 5V is applied to PA0

Have I missed the register settings?

2 REPLIES 2
Posted on September 15, 2017 at 10:27

Hello

NVIC is not configured to give EXTI Interrupts.

EXTI interrupt handler is commented...           //void EXTI0_IRQHandler(void)

 HAL_GPIO_EXTI_Callback   is called by HAL_GPIO_EXTI_IRQHandler , but the second is commented

So..

Enable NVIC's  EXTI_0 n Interrupt,  define EXTI0_IRQHandler , and write your code inside the handler.

Kang Sung Gu
Associate II
Posted on September 15, 2017 at 13:38

Thanks to you

My misstake is not declare 'HAL_NVIC_EnableIRQ(EXTI0_IRQn) '

static void MX_GPIO_Init(void){

.

.

.

HAL_NVIC_EnableIRQ(EXTI0_IRQn);

}