Skip to main content
ZKURT.1
Senior
December 9, 2021
Question

Hi. I have a question for you. I am using stm32l0. In order to power a module, I must use the same pin of the microprocessor as both input and output. What functions can I do this? I wish you a good day

  • December 9, 2021
  • 4 replies
  • 968 views

Do this with Arduino"

#define OutputSDIO() pinMode(SDIO,OUTPUT)

#define InputSDIO() pinMode(SDIO,INPUT)" functions. What functions can I do this using stm32cubeide?

This topic has been closed for replies.

4 replies

waclawek.jan
Super User
December 9, 2021

If you need to read state of an (open collector) pin set to output, just set the pin as output, its input level can be read regardless of that.

If you need to switch between input and output dynamically, change the given pin's setting in GPIO_MODER, read the GPIO chapter in RM.

I don't use Cube/HAL.

JW

TDK
December 9, 2021

HAL_GPIO_Init can be used to initialize pins in input or output mode. STM32CubeMX will generate example initialization code for you.

For example, this initializes PA0 in input mode:

 __HAL_RCC_GPIOA_CLK_ENABLE();
 
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 GPIO_InitStruct.Pin = GPIO_PIN_0;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

"If you feel a post has answered your question, please click ""Accept as Solution""."
ZKURT.1
ZKURT.1Author
Senior
December 10, 2021

0693W00000Ho8G0QAJ.pngHi. first of all thank you very much. How can I fix this error?

Tesla DeLorean
Guru
December 10, 2021

Create the variable you are using. You could do so locally within the subroutine.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..