IrDA 与其他红外协议的奇妙世界The Fascinating World of IrDA and Other Infrared Protocols


AI free token/AI免费积分
IrDA 与其他红外协议的奇妙世界

红外(IR)通信技术可能是最具影响力的技术之一,同时也是最不张扬的技术之一。由于红外通信通常具有很强的方向性,而且往往仅限于低数据传输速率,许多人对此不屑一顾,认为它除了让电视遥控器工作之外几乎毫无用处,顶多再加一些不太受欢迎的工业设备,比如电表的红外接口。

这其实有些可惜,因为电视遥控器恰恰说明了为什么在某些场合你需要定向通信;而任何与蓝牙配对搏斗过的人,都能体会到“只要对准设备就能工作”的价值。红外协议还具有天然的隐私保护优势——墙壁和其他障碍物会阻挡信号,而可被利用的蓝牙设备却会“友好地”向邻居和路人广播自己。

自然而然,消费类红外协议最古老的用途之一就是那历史悠久的红外遥控器。早期的电视机使用有线和超声波遥控器,后者通过简单的超声波音调来传输指令;而随着红外协议的诞生以及廉价 MCU 的出现,人们得以构建更复杂的通信协议。其中,NEC、Sony IR (SIRC) 和 Philips 协议可能是最知名、使用最广泛的协议。

这些协议采用约 38 kHz 的载波,常用的 NEC 协议使用脉冲间隔编码——一种幅移键控形式——而 Philips RC-5 协议则使用曼彻斯特编码。在这些编码方式中,协议定义了各种比特字段和其他数值,接收端可据此判断自己是否为目标设备,以及用户希望执行的命令。

如今,那些廉价而实用的 RGB 灯带及其他小设备附带的遥控器,往往同样使用 NEC 协议;网上也有许多基于 MCU 的项目,只需一个简单的红外 LED 即可直接控制这些小设备。

例如,[eleksaggr] 在 GitHub 上基于 STM32F0 的项目,就是针对常见的 24 键 RGB 遥控器的实现。德州仪器为 MSP430 提供的《红外遥控实现》应用笔记也包含调制和编码方案的概览,以及如何实现遥控器的方法。

许多智能手机曾经——或仍然——具备红外遥控发射器功能,能够以同样的载波频率和多种协议来控制几乎所有采用红外遥控的设备。理论上,在智能手机时代,这意味着每个人口袋里随时都有一个万能遥控器,但由于红外发射器如今已相当罕见,这一愿景并未实现。如果你最近购买的智能手机仍带有红外发射器,它很可能是中国品牌,这多少有些可惜,因为红外遥控器仍被用于那么多设备。

当然,红外遥控只是一个特定的应用场景,但红外通信能发送的远不止是基础指令集。最著名的标准当属 IrDA,即 Infrared Data Association(红外数据协会),该协会定义了各种标准。

IrDA 的基本原理其实与遥控协议相同,只是设计上能实现更高的传输速度。这通过多种编码、调制及其他技术实现,这些技术在非红外无线通信中也很常见。由此可达到多种速度等级,定义为:

此外,还存在一系列衍生协议,如 IrSimple,可让手机、打印机和显示屏之间轻松共享图片。所有这些通常使用相同的 IrDA 软件栈,但 IrSimple 等特殊版本对其进行了优化,使传输一张 500 kB 的图片只需不到一秒钟。

所有通信通常以半双工方式进行,因为发送端的干扰往往太大,会导致收发器的接收端无法可靠接收数据。两端之间的距离最长可达两米,而低功耗版本则缩短至约 20 cm。

在这些速度范围内,你可以根据设备需求选择合适的模式。例如,电能表完全能满足 IrDA-SIR 协议的要求,这种低功耗、低速的协议甚至可以在这些电表中最基本的 MCU 上通过 bit-banging 实现,只需在引脚上连接一个简单的红外收发器。

藏在你家配电箱里或其他安装位置的普通电表,必须与安装环境隔离,因此需要某种低功耗、低速率的无线接口。只需在外壳上设置一个红外透明窗口,读取设备就可以贴近该窗口,快速查询电表获取必要信息。

同样的功能也出现在热量表和其他需要此类基础读数功能的设备上。在这里,安全性不仅依赖红外通信链路的短距离视距要求,还通过包含加密密码交换的登录过程来管理。

尽管 IrDA-SIR 过去常用于此处,如今 DLMS/COSEM(也称 IEC 62056)更加常见。虽然基于无线电的自动抄表(AMR)也有使用,但这种短距离协议具有明确的隐私优势——视距特性意味着读取器必须真正站在电表前方才能工作,而射频无线方案则不然。

这种隐私优势是否重要取决于具体情境,但相较于在电表中塞入蓝牙或 Wi-Fi 模块并处理随之而来的问题,其低功耗需求无疑令人难以反驳。

虽然手持游戏机似乎直接从 Game Boy 的连接线跳到了任天堂 3DS 及其后续机型的 Wi-Fi 传输,但 3DS 其实配备了一个红外通信端口。其目的是为原版 3DS 支持 Circle Pad Pro 和 Amiibo 读写器等外设,因为原版 3DS 并未配备 New Nintendo 3DS 上的 NFC 读写器。

事实证明,3DS 使用 IrDA-SIR 来实现此扩展功能,例如 Circle Pad Pro 采用 96000 波特率。由于该外设仅用于添加第二个摇杆以匹配内置左摇杆,因此不需要大量带宽。

至于外置 NFC 读写器,它同样属于低带宽应用,因此利用同一红外端口为旧款 3DS 提供此新功能,而非将其设为 New 3DS 独有,是很合理的选择。尽管那时也可以使用蓝牙,但 3DS 并未内置蓝牙;再看看任天堂 Switch 的 Joy-Con,显然它们在功耗和电路复杂度上都稍高一些。

当低功耗和视距特性是优势,而非“你到底在和哪个外设配对”的困扰来源时,采用红外通信就十分合理。

如果你想自制红外接收器、发射器甚至收发器方案,有许多选择。也许最令人兴奋的是,即使你想使用 IrDA 这样的协议,许多 MCU 的 UART 模块本身就集成了该功能。例如,在 Espressif 的 ESP32 MCU 上,你可以查看其多种 UART 模式,除了标准 UART 功能外,还能选择 IrDA 和 RS485。

此外,还有专用的 IrDA 编解码 IC,如 MCP2120。它可为任何不直接支持 IrDA-SIR 的 UART 接口提供该协议支持。你也可以使用如 Vishay TFDU4101 红外收发器,它将包括红外元件在内的所有功能集成在一个封装中。

如果你更倾向于折腾 NEC、Sony 和 Philips 遥控协议,那么常见的 VS1838b 可为 38 kHz 应用提供与 Vishay 器件类似的解决方案。这款红外接收器负责所有接收、解调、放大等任务,而接收端的 MCU 只需解析收到的数据。

本文来源:https://hackaday.com/2026/10/26/the-fascinating-world-of-irda-and-other-infrared-protocols/
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

Infrared (IR) communication technologies are probably one of the most influential, yet also one of the least flashiest. The fact that IR communication tends to be highly directional and often limited to low data rate leads many people to scoff at it, deeming it barely worthy of more than making TV remotes work, perhaps along with some unloved industrial gear like the IR interface of electrical meters.

This is a shame, because TV remotes are a good example of why sometimes you want something that is directional, and anyone who has battled with Bluetooth pairing can attest to the value of things simply working by pointing it at the device. IR protocols also have the advantage of inherent privacy protection as walls and other obstacles will block the signal, unlike that of an exploitable Bluetooth device which happily advertises to your neighbors and passersby.

For reasons like the above – as well as their simplicity and hackability – IR protocols are worthy of a detailed look.

Naturally, one of the oldest uses of consumer IR protocols is that of the venerable IR remote control. Initially TVs used wired and ultrasonic remote controls, with the latter using simple ultrasonic tones to transfer a command, but with IR protocols and the advent of cheap MCUs it became possible to create extensive communication protocols. Of these the NEC, Sony IR (SIRC) and Philips protocols are probably the most well-known and most used.

These use an approximately 38 kHz carrier, with the common NEC protocol using pulse distance encoding – a form of amplitude-shift keying – and the Philips RC-5 protocol using Manchester encoding . Within this encoding, these protocols define various bit fields and other values that can be used by a receiver to determine whether it’s being targeted, and if so what command the user wishes to have performed.

When it comes to those cheap-and-cheerful remotes that you get with just about any RGB light strip and others gadgets these days, they tend to use the same NEC protocol, with many MCU-based projects around that can control these gadgets directly with a simple IR LED.

For example t his STM32F0-based project by [eleksaggr] on GitHub that targets the common 24-key RGB remotes. This Infrared Remote Control Implementation application note by Texas Instruments for the MSP430, which contains a good overview of the modulation and encoding schemes, as well as how to implement a remote control.

Many smartphones have – or used to have – an IR blaster feature that can target the same carrier frequency and a range of protocols to control just about anything that is IR remote controlled. In a world of smartphones this would theoretically mean that everyone has a universal remote in their pocket at any time, if it wasn’t for IR blasters becoming pretty rare. If your recently purchased smartphone still has an IR blaster, it’s very likely a Chinese brand, which is a shame as IR remotes are still used for so many things.

Of course, IR remotes are quite a specific use case, but you can send a lot more than just a basic set of commands to a device. The most well-known standard here is IrDA , which stands for Infrared Data Association, the association which defined the various standards.

The basic principles behind IrDA remain effectively the same as with the remote control protocols, just designed to be capable of far higher transfer speeds. This is accomplished through various types of encoding, modulation and other techniques also observed with non-IR forms of wireless communication. Using this a range of speeds are possible, defined as:

In addition a range of derived protocols exist such as IrSimple that allows for easy sharing of images between phones, printers, and displays. All of this uses generally the same IrDA software stack, though the special versions such as IrSimple optimize it to make transfers take less than a second for a 500 kB picture.

All communication generally happens in half-duplex, as the sending side tends to produce too much interference for the receiving side of the transceiver to reliably receive data. Distance between the two sides can be as much as two meters, though the lower power versions shrink that down to 20 cm or thereabouts.

Within this range of speeds you can pick whatever the device needs. Power meters, for instance, are plenty happy with the IrDA-SIR protocol, which is low-power and speed enough to bitbang on even a basic MCU in these meters with just a basic IR transceiver attached to its pins.

The Fascinating World of IrDA and Other Infrared Protocols

The humble power meter that lurks in your utility closet or wherever else it is installed has to be shielded from whatever environment it is installed in, ergo they require some kind of low-power, low-speed wireless interface. Using nothing but an IR-transparent window on the enclosure it is then possible for a read-out device to be pressed up to said window, where it’ll quickly query the device for the necessary information.

This same feature is also found on heat meters and other types of devices where such basic read-out functionality is required. Here security is managed by not only the short-distance, line-of-sight requirement of an IR communication link, but also by having a sign-on involving an encrypted password exchange.

Although IrDA-SIR was commonly used here, these days DLMS/COSEM, also known as IEC 62056 , is much more common. While radio-based forms of automatic meter reading ( AMR ) are also used, short-range protocols like this have a definite privacy advantage, with the line-of-sight feature meaning that the reader has to be literally in front of the meter to work, unlike with RF wireless approaches.

Whether this privacy aspect is important depends on the situation, but it’s hard to argue with the low power requirements compared to stuffing a Bluetooth or Wi-Fi module into the meter and dealing with its implications.

Although it may seem that handheld game consoles went straight from the Game Boy’s link cable to Wi-Fi transfers on the Nintendo 3DS beyond, it featured an IR communication port. This was intended to support peripherals like the Circle Pad Pro and the Amiibo reader/writer device for the original 3DS as it did not feature the NFC reader of the New Nintendo 3DS.

As it turns out, the 3DS uses irDA-SIR for this expansion feature, with e.g. the Circle Pad Pro using a 96000 baud rate. Since this peripheral merely is there to add a second circle pad to match the built-in left one, it doesn’t need a lot of bandwidth.

In the case of the external NFC reader, this was a similar low bandwidth application where it made a lot of sense to use this same IR port to provide this new feature to older 3DS consoles, instead of making it a New 3DS-exclusive feature. Although one could have used Bluetooth for this even back then, the 3DS console did not include Bluetooth, and when looking at e.g. the Joycons of the Nintendo Switch it’s clear that they are a tad more power hungry and complex circuitry-wise.

When low-power and line-of-sight are benefits rather than a potential source of confusion of which peripheral you’re trying to pair with, it can make a lot of sense.

If you’re feeling like making your own IR receiver, receiver or even transceiver solution, there are many options. Perhaps the most exciting aspect is that even if you want to use something like IrDA, this feature is often part of the UART in many MCUs. In the case of Espressif’s ESP32 MCUs, for example, you can look at its list of potential UART modes and note that you can pick IrDA as well as RS485 in addition to plain UART functionality.

There are also dedicated IrDA encoder/decoder ICs, such as the MCP2120 . This gets you IrDA-SIR support for any UART interface that does not directly implement this protocol. You can also use something like the Vishay TFDU4101 IrDA transceiver that integrates everything including the IR elements into a single package.

If you’re more about messing with NEC, Sony and Philips remote control protocols, then a common part like the VS1838b provides a similar solution to the Vishay part for 38 kHz applications. This IR receiver handles all the receiving, demodulating, amplification and other tasks, leaving it to the receiving MCU to parse the received data.

This of course just barely scratches the surface of everything IR communication-related, so feel free to chime in with your own info dumps and requests for additional topics to cover.

暂无评论,快来发表第一条评论吧!No comments yet. Be the first!

📮 需求咨询📮 Inquiry