STM32CUBEMX(5) – Custom IR NEC decoding, timer TIM capture method
Overview
This article introduces how to use STM32CubeMX to decode IR waveforms and print them via serial port.
Hardware Preparation
First of all, you need to prepare a development board, here I prepared the NUCLEO-F030R8 development board:.
Select chip type
Configuring the clock source
Configuring the clock tree
The STM32F0 has a maximum main frequency of 48M, so a configuration of 48 is sufficient.
Serial port configuration
This experiment uses serial port 1 for serial communication, and the baud rate is configured to 115200.
Timer configuration
This time, channel 2 of timer 1 is used for detection, and the configuration is entered under.
Infrared receiver tube
The receiver tube of VS838 is used here as follows.
Infrared encoding
NEC protocol carrier: 38khz
The representation of its logic 1 and logic 0 is shown in the figure.
NEC protocol format.
Custom infrared encoding
The agreement is as follows.
In main.c, add the header file, if you don’t add it, you will get an error that identifier “FILE” is undefined.
Infrared receiver port definition
Function declaration and serial port redirection.
Infrared receiver code
[4400,5000] is for capturing 4.5ms signal
[550,700] is for capturing 560us data 0 signal
[1100,1250] is used to capture 1120us data 1 signal
[2000,2500] is used to capture the 2240us cutoff signal
Result demonstration
Infrared continuously send 5 times the code value, send respectively
1011(11)
11 1010(58)
11 0001(49)
11 1111(63)
11 0011(51)
are shown below, respectively.
Related posts:
- Chip on board | Read the car regulations in one article
- Real-time efficiency measurements of electric vehicle inverters and motors
- With 40% more CPU performance and twice the graphics power, the UP Squared V2 delivers more power at the same low cost
- Docker tutorial: How to create and run Helix QAC as a container