As always, use CubeMX for peripheral configuration.
Using the level mode requires two captures, and sending a 10us trigger pulse requires a delay. 103VBT6 does not have many timers, so the UART port is more convenient.
Hardware Configuration:
1) Set the UART baud rate to 9600
2) Enable NVIC interrupt
software:
I use US-100 to measure the consumption of pellets in the hopper. The project uses FreeRTOS system.
1)
Enable UART2 port monitoring in the main function
HAL_UART_Receive_IT(&huart2, rx_data_sonic, 2);
After triggering the module, it will return 2 bytes of data, and we will read 2 bytes directly here.
2)
In the Task, it is triggered every 10 seconds and a byte 0x55 is sent. The task runs every 20ms and uses a count.
check_interval++;
if (check_interval >= 499) {
HAL_UART_Transmit(&huart2, &command_sonic, 1, 1);
check_interval = 0;
}
3)
Do calculations in the interrupt callback function.
The hopper height is 50 cm, so the returned value is limited. For example, if the hopper cover is opened, the data of several meters measured will be thrown away. There is no need to consider the case where the hopper is opened.
//Ultrasonic data
if (huart->Instance == USART2) {
uint16_t distance = rx_data_sonic[0]*256 + rx_data_sonic[1];
if (Q_SonicDataHandle != NULL) {
if (distance < 500) {
osMessagePut(Q_SonicDataHandle, (uint32_t)distance, 0);
}
}
HAL_UART_Receive_IT(&huart2, rx_data_sonic, 2);
}
At the end of the statement, you need to start the serial port interrupt monitoring again.
Previous article:STM32 timer single pulse output
Next article:STM32 port mode configuration
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- SimpleLink MCU code migration guide: CC1310 from VQFN48 (7×7) to VQFN32 (5×5) code migration process reference
- Welcome the new moderator of the "201420208012" eSports
- [Raspberry Pi Pico Review] ADC External Benchmark vs. Onboard Benchmark
- Share and discuss: How to quickly determine whether a domestic chip is truly self-developed or just a sham?
- Do DC powered devices have common mode interference?
- Allegro photo-painting problem
- The PCIE communication problem that has troubled me for three days - please help!
- Typical Vacuum Cleaner/Robot Sweeper BMS Topology
- TI's crystal-free SimpleLink wireless MCU helps you easily achieve crystal-free
- Open source sharing of a 4-axis brushless motor FOC control board project