IR Remote with STM32
Today in this tutorial I am going to interface IR Remote with STM32 microcontroller. IR Remote Controllers and receivers follow some standard protocols for sending and receiving data. Some of these protocols are NEC , JVC , SIRC etc. Here we will be discussing only the NEC protocol. I will also use LCD16x2 to display the key pressed on the remote. But first let’s see what NEC protocol is.
In NEC Protocol, a logic 0 is indicated by 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms and a logic 1 by 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms.
Whenever a key is pressed, the following is transmitted:-
1. A 9 ms leading pulse
2. A 4.5 ms space
3. The 8-bit address
4. The 8-bit logical inverse of the address
5. The 8-bit command
6. The 8-bit logical inverse of the command
7. Finally a 562.5µs pulse burst to show end of message transmission
How to Decode
Decoding any IR protocol is not difficult at all. The IR receiver is a photodiode and pre-amplifier that converts the IR light into an electrical signal. It converts the active HIGH signal to active LOW. Also the signal pulse are continuous as shown in the picture below
Ok so in order to decode first we have to wait for the input pin to go low. Once the pin is LOW, we will wait for the pin to go HIGH. This should take around 9ms.
Again wait for the pin to go low, which should take around 4.5 ms. And this will conclude the Start of Frame.
Now we are going to read the 32 bits and store them in a variable. To read a bit, we are going to check the length of the SPACE followed by the 562.5µs. If this length is more than 1 ms, that means the bit is ‘1’. If the length is less than 1 ms the bit is ‘0’.
Next we need to assign the values to the key pressed on the Remote. I will also print these characters on the LCD. Below is the code to do that.
. . . . . DOWNLOAD . . . . .
You can buy me acontrollerstech
coffeeSensor by clicking DONATE OR Just click DOWNLOAD to download the code