2021-12-01 05:34 AM
2021-12-01 10:57 AM
For example, to set PA5 to analog mode:
GPIOA_MODER |= (3 << (5 * 2));
where 3 is 0b11 for Analog Mode as given by GPIOx_MODER description in the GPIO chapter of RM; 5 is for PA5; 2 is because there are 2 bits per pin in GPIOx_MODER.
JW
2021-12-01 06:40 AM
Please include your chip number in posts.
Set the appropriate bits within GPIOx->MODER to analog mode.
2021-12-01 07:32 AM
The chip I'm using is STM32L4R5ZI-P.
My question is what if I want to switch only a particular bit to Analog mode without switching whole GPIO PORT into Analog mode before entering to Stop2mode..
2021-12-01 07:37 AM
> My question is what if I want to switch only a particular bit to Analog mode without switching whole GPIO PORT into Analog mode before entering to Stop2mode..
Yes, that is the question I answered.
Set the bits associated with that pin to analog mode and leave the bits associated with other pins unmodified.
You can also use HAL_GPIO_Init to do this.
2021-12-01 09:23 AM
Thanks for your response @TDK
Bit set is quite confusing,
Can you please help me with that?
2021-12-01 10:57 AM
For example, to set PA5 to analog mode:
GPIOA_MODER |= (3 << (5 * 2));
where 3 is 0b11 for Analog Mode as given by GPIOx_MODER description in the GPIO chapter of RM; 5 is for PA5; 2 is because there are 2 bits per pin in GPIOx_MODER.
JW
2021-12-01 11:29 AM
If you're not comfortable with register-level manipulation, I would suggest sticking with HAL.
To change PA5 to analog mode:
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2021-12-01 09:52 PM
Thank you soo much @TDK (ST Employee)
Your explanation was very informative.
2021-12-01 09:55 PM
Much appreciated for the explanation, Thank you very much@waclawek.jan