admin管理员组文章数量:1405514
I am working on an STM32F446RE-based traffic light system using Eclipse IDE. The project uses a host-to-target communication method to control GPIOs remotely.
The code is supposed to turn on and off Red, Yellow, and Green LEDs based on the state of a GPIO input (PB10). However, when I use multiple HAL_GPIO_WritePin() calls in sequence, the behavior is incorrect.
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10) == GPIO_PIN_RESET) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); // Red ON [Pedestrain crossing]
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET); // Yellow OFF
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); // Green OFF
}
else {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); // Red ON
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET); // Yellow OFF
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); // Green OFF
HAL_Delay(2000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); // Red OFF
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); // Green ON
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET); // Yellow OFF
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); // Green OFF
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET); // Yellow ON
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); // Red OFF
HAL_Delay(500);
}
If I use only the first two HAL_GPIO_WritePin() calls, the Red and Yellow LEDs work correctly. If I add a third HAL_GPIO_WritePin() call for the Green LED, the code does not behave as expected. Sometimes, the LEDs do not toggle correctly, or they remain in the wrong state.
Adding a delay does not fix the issue. Since I am using host-to-target communication, I may not be seeing the real-time execution flow.
- Since multiple HAL_GPIO_WritePin() calls are executed sequentially, the final LED state may be getting overridden?
- If the commands are being sent too quickly, the target may not register them correctly?
- Why does adding a third HAL_GPIO_WritePin() call disrupt the expected LED behavior?
- Is there a limitation in how GPIO writes are processed in STM32 when using host-to-target communication?
- What debugging steps should I take to diagnose and fix this issue?
本文标签: eclipseSTM32 Traffic Light Code HALGPIOWritePin api Not Working as ExpectedStack Overflow
版权声明:本文标题:eclipse - STM32 Traffic Light Code HAL_GPIO_WritePin api Not Working as Expected - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744921008a2632292.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论