cancel
Showing results for 
Search instead for 
Did you mean: 

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

ZKURT.1
Senior

Do this with Arduino"

#define OutputSDIO() pinMode(SDIO,OUTPUT)

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

4 REPLIES 4

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
Guru

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
Senior

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

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

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