To get up and running quickly with this sample, follow the steps below:
-
Hook the HC-SR04 Sensor to
PB10
{trigger
} andPB11
{echo
} pins on the board -
Flash
./Dist/ultrasonic.bin
in to your dev kit. -
Open Serial to view data
For a detailed write up, read below
-
Set
HSE
toCrystal/Ceramic Resonator
and disableLSE
as shown -
Under timer config set
Clock Source
toInternal Clock
forTIM1
. -
Set serial mode to
Asynchronous
for bothUSART1
andUSART2
and ensuregloabl interrupt
is enabled underNVIC Settings
-
See below clock configuration.
- Toggle
PLL
andPLLCLK
- Set input frequency to
8Mhz
- Toggle
-
You might want to set the multiplier
PLLMul
to 11 or above then clickResolve Clock Issues
SAVE AND GENERATE PROJECT
- Inside
./Core/Inc/main.h
ensure you have the following underPrivate defines
.
#define TRIGGER_PIN GPIO_PIN_10
#define TRIGGER_PORT GPIOB
#define ECHO_PIN GPIO_PIN_11
#define ECHO_PORT GPIOB
- Note that the line shown below is commented under
./Core/Src/syscalls.c
extern int __io_putchar(int ch) __attribute__((weak));
-
Also note that an IRQ handler is required for USART1; see
./Core/Src/stm32f1xx_it.c
. -
Note the differences under
./Core/{*}/usart.{*}
-
Note custom implementation of µSeconds delay inside
./Core/{*}/main.{*}