Realize communication between microcontrollers through infrared interface

Publisher:EnigmaticCharmLatest update time:2018-03-01 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  Infrared is an electromagnetic wave with a wavelength of 750nm to 1mm. Its frequency is higher than microwaves but lower than visible light. It is a kind of light that is invisible to human eyes. Infrared communication generally uses near-infrared in the infrared band with a wavelength of 0.75μm to 25μm. At present, radio waves and microwaves have been widely used in long-distance wireless communications. However, due to the short wavelength of infrared and poor diffraction ability to obstacles, it is more suitable for applications where short-distance wireless communication is required for point-to-point linear data transmission. From the perspective of application areas, infrared communication is mainly used in remote control and data communication. The general data transmission rate of the infrared communication port can reach 2400bit/s to 115.2kbit/s, and some can even reach 4Mbit/s.
  
  This design realizes communication between single-chip microcomputers through an infrared interface. The two parties in communication agree that the sender is machine A and the receiver is machine B. Machine A sends a set of data to machine B. If the data received by machine B is correct, it sends 0x55 to machine A; if the data received by machine B is incorrect, it sends 0xFF to machine A. After receiving 0xFF, the receiver A retransmits the data.
  
  Infrared communication technology mainly uses infrared transmitters and infrared receivers to complete the wireless transmission and reception of signals. At the transmitting end, the transmitted digital signal is appropriately modulated and sent to the electro-optical conversion circuit to drive the infrared light emitting diode to emit infrared light pulses; at the receiving end, the infrared receiver performs photoelectric inverse conversion on the received infrared signal, and performs corresponding demodulation to restore the original signal, as shown in the figure below.

Basic principle block diagram of infrared communication interface

  The hardware circuit of infrared communication consists of two parts: the transmitting circuit and the receiving circuit. As shown in the figure below, the upper part of the figure is the transmitting circuit, and the lower part is the receiving circuit. Of course, as the other party of the communication, there is also a similar set of transmitting and receiving circuits.

  Since the light response frequency of the infrared receiving module TSOP1838 used in the system is 38kHz, in order to reduce the bit error rate of data exchange, the carrier frequency of the infrared transmitting part should also be adjusted to 38kHz. The carrier signal is generated by the internal timer of the single-chip computer 89C51. The carrier signal is output from the Pl.0 pin and modulated by the 74HC08 and gate to the data output terminal TXD. After being amplified by the transistor T1, the transmitting tube TSAL6200 emits pulsating infrared light. Its transmission power can be changed by adjusting its current limiting resistor R3.
  
  In order to improve the waveform of the received signal, the infrared receiving circuit will perform two-stage inversion shaping on its output signal. The purpose of using an AND gate in this receiving circuit is that if the system has other communication interfaces, the data receiving end of the communication interface can also send data to the RXD pin through the AND gate. Of course, users can also use the AND gate circuit instead of the second-stage NOT gate to directly connect the output of the RXD pin.

Infrared communication hardware circuit

  Compared with conventional wired communication, infrared communication only uses different transmission media, so the communication procedure is similar to the above description. The only difference is that infrared communication still has the problem of carrier wave. Therefore, the procedure only includes serial port initialization, timer initialization, timer interrupt service program, communication receiving and sending program, etc.
  
  1. Serial port initialization program init() The
  
  serial port initialization program is as follows. The serial port works in mode 1 with a baud rate of 9600 bit/s. The timer T0 of the microcontroller generates a 38 kHz carrier signal through a timer interrupt, and the T1 timer is used as a baud rate generator.


  The program uses timer T0 to generate interrupts of a certain frequency , and controls the pin output high and low levels .

  In this way, the carrier signal is generated. The interrupt service program code of timer TO is as follows:
  
  Note: When writing the program, the timing interrupt for generating the carrier frequency is only turned on when sending. When the sending is completed, turn off the interrupt and set Pl.0 to 0.

  2. Machine A sends subroutine voidsend()
  
  Machine A sends subroutine send0 to complete the function of machine A sending data. Calculate the checksum and send the data, wait for machine B to respond, if machine B responds correctly, return from the subroutine, otherwise send the data again and wait for machine B to respond. The program code is as follows:

  3. The receiving program of machine B voidrecv()
  
  The receiving program of machine B receives data according to the specified communication signal. It receives data and calculates the checksum. If the checksum is correct, it sends 0x55 to indicate that the data is correct. Otherwise, it sends 0xFF to indicate that the data is received incorrectly. The program code is as follows:

  When designing and using infrared communication, the following issues should be noted:
  
  Distance and power issues: The distance of infrared communication mainly depends on the intensity (current) of the emission.

  ·The speed of communication: Since the carrier frequency of the modulation is 38kHz, in order to receive the transmitted signal well, it is recommended that the data transmission rate set by the single-chip microcomputer should not exceed 9600bit/s.
  
  ·When using, the angle between the transmitting tube and the receiving tube should be considered. The larger the angle, the closer the receiving distance will be, or even no reception.
  
  ·For the simplex mode, the sender only retains the sending part of the circuit, and the receiver only retains the receiving part of the circuit. For example, an active remote control that does not need to return information has only a sending circuit, while a passive receiving controller has only a receiving circuit.
  
  ·The carrier frequency can also be obtained by other circuits that can generate oscillating square wave signals, such as the 555 circuit.
  
  ·At present, there are also dedicated infrared modules that transmit and receive, transmitting modules that only transmit but not receive, and receiving modules that only receive but not transmit on the market. Most of these modules integrate modulation, drive, demodulation and other circuits. Users only need to choose a good model and master its interface relationship.


Reference address:Realize communication between microcontrollers through infrared interface

Previous article:Using data frames to realize multi-machine communication between single-chip microcomputers
Next article:Serial communication between multiple microcontrollers

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号