cancel
Showing results for 
Search instead for 
Did you mean: 

Switching alternate functions for on input pin

papageno
Associate III

Hello experts,

I am using a stm32F446RET6 (HAL and C) and I am using the PA1 input pin for receiving a serial stream with the TIM2 Channel for frequency and logic detection. This Input capture timer works perfectly. But prior to decode the stream I first need to check if there is an active signal on that pin. So my question concerns the use of an alternate function on the PA1 pin, for example as EXTI or GPIO. Is it possible to switch from EXTI or GPIO input to the TIM2 CH2 without destroying all the settings that have been done. I read that there is a way to use the GPIOx_AFRL register.

i would be thankful to anybody who already did that. I tried several things and so far it s not working, it is not as trivial as expected obviously. The goal would be to use the PA1 pin as EXTI or GPIO input to detect if the signal is present and if positive switch the pin back to the TIM2 Channel for logic decoding.

Regards,

5 REPLIES 5

You don't need to switch anything. While the pin is set for timer input capture, GPIO_IDR still reflects the input state of the pin and, if set up for that given pin, EXTI works, too.

JW

Thank you jan,

You mean that even if the pin was configured as TIM2_CH2 and not as GPIO_input, i can still read (GPIOA->IDR & pin) the value or trigger an exception without setting anything ? I will try that.

Regards,

pap

> You mean that even if the pin was configured as TIM2_CH2 and not as GPIO_input, i can still read (GPIOA->IDR & pin) the value

Yes.

> trigger an exception without setting anything

Well, you need to have the proper port selected in the respective SYSCFG_EXTICRx, but PAx is by default; and of course you have to have EXTI set up properly.

JW

Thanks Jan,

It worked with ready GPIOA->IDR & PINA1 with a delay between readings closed to the signal frequency, arbitrary values are 2 or 0 which means the signal is toggling. Probably the EXTI would have been a more reliable solution, but not enough time to test that solution. So thank you Jan.

Regards.

Pap

thanks Jan,

i will give a try to EXTI later on, so far the port reading is satisfying.

regards,

Pap