Our Latest News

STM32CUBEMX(5) – Custom IR NEC decoding, timer TIM capture method

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.

    GET A FREE QUOTE

    FPGA IC & FULL BOM LIST

    We'd love to

    hear from you

    Highlight multiple sections with this eye-catching call to action style.

      Contact Us

      Exhibition Bay South Squre, Fuhai Bao’an Shenzhen China

      • Sales@ebics.com
      • +86.755.27389663