Question
Re: Tristating GPIO as an output
I used the code below but not working , did you find the solution ?
void SetPinTristate(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; // Switch to input mode
GPIO_InitStruct.Pull = GPIO_NOPULL; // No pull-up, No pull-down
HAL_GPIO_Init(GPIOx, &GPIO_InitStruct);
}
void SetPinOutput(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Push-Pull Output
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOx, &GPIO_InitStruct);
}
while (1)
{
SetPinOutput(GPIOA, GPIO_PIN_1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
HAL_Delay(1000);
SetPinTristate(GPIOA, GPIO_PIN_1); // Switch to Tri-State (Hi-Z)
HAL_Delay(1000);
}
