RS-485 communication card and its application

Publisher:浅唱梦幻Latest update time:2006-05-07 Source: 电子产品世界 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Abstract: This article introduces the characteristics and usage of the RS-485 communication card method, as well as the practical method of using VB5 programming to realize communication between a microcomputer and a microcontroller and the issues that should be paid attention to.

    Keywords: RS-485 communication, microcomputer serial communication, VB communication programming

In the field of industrial control, data collection and transmission are regular tasks. RS-485 protocol communication is widely used in the field of industrial control because it adopts differential reception and has strong ability to suppress common mode interference.

Two methods to implement RS-485 communication

The microcomputer standard communication adapter meets the RS-232C protocol standard. Under the condition that the waveform distortion is less than 10%, the maximum transmission distance is 50 feet (about 15.24 meters), and the maximum transmission rate is less than 20kbps. It cannot meet the requirements of industrial field data over long distances and high speeds. rate transmission requirements. Two methods can be used to implement RS-485 protocol communication in a microcomputer: the first is to use an RS-232C and RS-485 conversion interface device; the second is to use an RS-485 communication card, which is inserted into the expansion slot of the microcomputer motherboard. The advantage of using the first method is that the hardware device is simple to install and the software programming is relatively simple; the disadvantage is that the communication rate is still limited to 20kbps (limitation of the RS-232C protocol). The advantage of the second method is that the communication rate is relatively high, up to 921.6kbps; the disadvantage is that the communication card needs to be installed on the microcomputer expansion slot, and the software needs to install the communication card driver and make necessary settings.

Characteristics and connection methods of RS-485 communication card

The communication baud rate of the RS-485 communication card is optional from 50bps to 921.6kbps; usually each card has two communication ports, each supporting 32 nodes, a total of 64 nodes; the software environment supports DOS, WINDOWS95, and WINDOWS NT. The communication connection mode can adopt point-to-point half-duplex mode, point-to-point full-duplex mode, multi-point half-duplex mode and multi-point full-duplex mode.

Application of RS-485 communication card

Install driver

The RS-485 communication card comes with a driver. When using the communication card for the first time, you must first install the driver and set the I/O address, interrupt number, communication port number, etc. of the communication card. There is no need to set it again when the system is running in the future.

Features of VB communication software

The communication software in this example is implemented under the WINDOWS95 platform using VB5.0, and the data is stored in the form of random files. Since WINDOWS does not support direct access to system I/O ports, a simple way to implement serial communication under WINDOWS is to use the communication software MSComm provided by VB. Several of the most important and commonly used attributes in MSComm software are: CommPort sets or returns the number of the communication port; its format is: MSComm.Comm Port=n, where no is any integer value from 1 to 99. If the port does not exist, an error will occur when opening the port using the PortOpen property.

Settings sets or returns parameters such as baud rate, data bits, stop bits, etc. For example: MSComm1.Settings="9600,N,8,1"

Among the parameters on the right side of the equal sign, each part represents the communication baud rate. The second part is the check mode, N means no check; E means even check; O means odd check; S means space check; M means sign check. The third part is the number of data bits. Finally, there are the number of stop bits.

PortOpen sets or returns the status of the communication port. If it is TRUE, the communication port is opened; if it is FALSE, the communication port is closed.

Input takes out the receive buffer and returns a string.

Output writes characters to the send buffer.

InBuffSize sets or returns the receive buffer byte value.

InputLen sets or returns the number of strings read each time when reading a string from the buffer; if InputLen is set to 0, when reading the buffer, the entire buffer content is read at one time.

letter of agreement

The physical layer communication protocol adopts the RS-485 standard; the link layer adopts character-oriented protocols; this example adopts the character-based communication protocols actually used by the author on site. The specific data (hexadecimal) format is shown in Table 1.

Table 1

prefix command code Data 1 Data 2 check suffix
FCH 00H~FEH 00H~FEH 00H~FEH Check word FFH
8 bits 8 bits 8 bits 8 bits 8 bits 8 bits

The command code contains the "data resend" command (when verification errors occur). If verification errors occur three times in a row, the system will alarm.

What is particularly mentioned is that this example program is to complete the serial communication between the microcomputer and the microcontroller system. The microcomputer uses the VB software platform and is programmed in the WINDOWS95 environment. Since VB communicates in character (ANSI code) under the WINDOWS environment, while the microcontroller system uses hexadecimal codes, during the communication process, VB must perform special conversion on the data in order to communicate with the microcontroller system.

The data output in the program can only be converted by the CHR() function so that VB can output hexadecimal data and the microcontroller system can receive it normally. See the program list for specific procedures.

Conclusion

With its high communication rate (921kbps), strong anti-interference ability and low price, RS-485 communication card has strong competitiveness in the field of industrial control and is of great practical value. The author successfully applied the RS-485 communication card to the serial communication between the microcomputer and the microcontroller data acquisition system. The microcomputer side used VB to compile the communication and data processing software, and the microcontroller side used assembly language programming. The use of CHR() function in VB for data conversion is the key to realizing hexadecimal data communication between microcomputer and microcontroller.

Reference address:RS-485 communication card and its application

Previous article:PC and laser range radar dual-channel high-speed data communication interface card
Next article:Application of keyboard interface in communication between microcontroller system and PC

Latest Industrial Control 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号