2025-07-15 10:07 PM
Hi everyone,
I'm currently working on an obstacle-avoiding robot using the STM32F407 Discovery board and I'm running into issues with testing my HC-SR04 ultrasonic sensor.
Hardware setup:
TRIG connected to PA0 (configured as push-pull output)
ECHO connected to PA1 (configured for TIM2_CH2 input capture mode)
Using TIM2 to measure pulse width via input capture on Channel 2
Running the code bare-metal (no HAL or CubeMX)
The issue:
I tried having Chat walk me thru how to use UART but that didn't work, so I tried testing the sensor by debugging it and see if the value for my distance changed in the expression window.
When I tried running it, it wouldn't work, so I tried stepping over to see where it broke, and its stopping on line 118-119, right after the while loop. I had this issue earlier with the for loop on 113, but GPT was able to help me thru that one, but so far I am stuck on this part.
I am doing this solo with GPT walking me thru it, so I am open to any and all pointers/advice.Appreciate for any help I could get. I basically just watched a beginner course off Udemy and dived right in.
Thanks in advance