Skip to main content
Graduate II
September 24, 2024
Question

GPIO mode change

  • September 24, 2024
  • 2 replies
  • 859 views

Hi, 

I set it to GPIO Input mode and am using it.

When I receive any signal during MCU operation, I want to convert it to Input -> EXTI mode.

I wrote these codes at the moment, but there seems to be a problem.

My Init code : 

GPIO_InitStruct.Pin = ADC_START_SIGNAL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ADC_START_SIGNAL_GPIO_Port, &GPIO_InitStruct);

How should I do it?

 

Thank you.

    This topic has been closed for replies.

    2 replies

    Graduate II
    September 24, 2024

    Hi,

    I don't use HAL for pin configuration, because it adds too much complexity.

    You will most likely find that HAL cannot re-configure a pin (that is - remove a previous configuration first). Find a function that puts the pin back to its 'reset' state first...

     

    Kind regards
    Pedro

    Super User
    September 24, 2024

    That is how you do it. The interrupts also need to be enabled with the relevant handling code inside of them. Perhaps configure the pin as EXTI and auto-generate the code to see what is needed, and then replicate that.

    It would be easier to configure it as EXTI at startup, and reconfigure to input. That way you would have the EXTI infrastructure in place. You could also leave it as EXTI and just disable the interrupt, since the pin is still an input.