2016-12-22 05:14 AM
Hi. I'm trying to remap a gpio pin from out to it but the following lines of code don't work.
Can someone help me?
I need to remap GPIOx, GPIO_Pin from out to in on the fly.
void DigitalInOut::SwitchToInput() {
HAL_GPIO_DeInit(GPIOx, GPIO_Pin); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = GPIO_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOx, &GPIO_InitStruct);}void DigitalInOut::SwitchToOutput() {
HAL_GPIO_DeInit(GPIOx, GPIO_Pin); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = GPIO_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOx, &GPIO_InitStruct);}2016-12-23 02:56 AM
Hi Denis,
Your issue is not clear. Could you please give more details: What STM32 product are you using? what do you want to do exactly? where have you found an issue?
Regards,
Khouloud.
2016-12-23 03:42 AM
Using CubeMX (hal) I have defined a pin as digital output to manage a lcd 2x16 display. OI need to convert it to digital input and then to digital output again. Is there a way? Can someone share an example?
2016-12-23 06:32 AM
Hello Denis, at the first sight your code should work. The one thing which I would recommend to check is that clock for the corresponding GPIO port is enabled. You can do it in debug session by checking the RCC registers. You can check there also the GPIO registers (for instance GPIOx_MODER for mode).
2016-12-23 03:14 PM
How do you know that that code does not work?
2017-01-03 12:23 AM
Solved by increasing the stack size.
2017-01-03 04:22 AM
Hi Denis,
Glad that your issue is solved
And thanks for sharing the solution, this may be helpful for other users.Khouloud.