About GPIO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 2:35 AM
I am using a nucleo l4r5zi.
​
I would like to use the GPIOs on this board as inputs and get the value of those inputs from software.Specifically, I would like to use PG2 to accomplish this.
​
I have the following setup and am inputting 3.3v into PG2, but for some reason I cannot read the value of the input.
​
・Pin initilization​
static void set_pin(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOG_CLK_ENABLE();
HAL_PWREx_EnableVddIO2();
/*Configure GPIO pin : PG2 */
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct)
}
​・Read
HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_2)
Are there any settings that are missing?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 5:43 AM
@Community member​
​
thank you for quick reply.
​
I added the following code before calling HAL_PWREx_EnableVddIO2, and it worked as expected.
__HAL_RCC_PWR_CLK_ENABLE
​However, I understand that this is a bit to enable the power interface clock.
Does this mean that I have to call the above function when using GPIO?
I had not called it before, but peripheral functions like UART were working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 3:26 AM
If in doubts, always start with reading out and checking all the relevant registers' content.
> HAL_PWREx_EnableVddIO2();
Have you enabled PWR clock in RCC before calling this function?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 5:15 AM
Hello,
You did not initialize: GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
If things do not work out the right way at first: use the MX configuration tool to generate initialization code and compare with what you have.
The MX code generator is not perfect but for getting your board up and running, it can save you a lot of time.
And for logic 0 do not forget to connect to the ground as you did not provide pullup or pulldown.
Best regards,
Johi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 5:43 AM
@Community member​
​
thank you for quick reply.
​
I added the following code before calling HAL_PWREx_EnableVddIO2, and it worked as expected.
__HAL_RCC_PWR_CLK_ENABLE
​However, I understand that this is a bit to enable the power interface clock.
Does this mean that I have to call the above function when using GPIO?
I had not called it before, but peripheral functions like UART were working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 6:16 AM
No.
Usually just do it once. I usually do it in SystemClock_Config()
Watch post power-on / standby operation
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 9:23 AM
To be able to use pins which are supplied from VDDIO2, i.e. PG2..PG15, you have to set PWR_CR2.IOSV. And to be able to do that, you have to enable PWR clock in RCC.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-10-09 9:45 AM
And one can disable that clock after the PWR is configured.
