Designing Microprocessor Based Instrumentation

Data Transmission

Local network with RS485

Networking 8051SBC with onboard RS485 Transceiver, 75176.

 

8051SBC's onboard serial port, RS232 and RS485.

The serial port, TxD and RxD signals are shared with RS232 and RS485 drivers. We see that TxD from 8051 chip can tie directly to both drivers chip directly. Instead the 8051 has only one bit RxD pin. So to accept two output bits, R1OUT from MAX232 and R from 75176, we will need AND gate to combine them. The output from AND gate can then tied to RxD input of 8051 chip. With this method, we can not have both drivers drive the AND gate the same time.

The signal that interfaces serial port to the driver chips is TTL level. Digital baseband is NRZ, (NON RETURN to ZERO). The RS232 is full duplex, transmit and receive at the same time. The RS485 is half duplex transmission. To send data, P1.3 must be logic '1'. And to receive data must be logic '0'. Suppose the RS232 is tied to terminal and the RS485 also tied to another RS485 device, when 8051 sends data through TxD pin, the terminal will display the packet that sent over RS485 network. We can use terminal as the debugging tool.

 

 

Industrial Standard RS485 Transceiver, 75176

The RS485 bus is balanced differential mode transmission. The bus has only two signals, A and B. The transmitter has output that shares with input of the receiver. The transmitter's output can release driver from the RS485 bus by disable control pin, T/R. At one time there will be only one driver activated, the rest must be in receiver mode (T/R = 0). The onboard RS485 driver uses P1.3 to control T/R signal.

 

Terminators (RT)

At both far-end RS485 cable, the terminators were inserted to provide loop current flowing and reduce ringing signal. The value must be approx. to cable characteristic's imepedance. The common value for RT is 120 Ohms.

MODBUS Protocol

Master-Slave Query-Response Cycle

The Master sends command to slave, say reading content of register number 1. Slave then replies with appropriate data.

 

MODBUS Framing

The MODBUS frame begins with COLON( 0x3A), destination address, source address, function code, data field, LRC (Longitudinal Redundancy Code), CR and LF.

Description here refers MODBUS with ASCII format. Destination and source address are formed by two bytes in ASCII code for example, the destination address is 10, it will be 0x31 and 0x30. The same for source address.

Function code also formed by two bytes ASCII code for example function code = 03, it will be 0x30 and 0x33.

Data field can be any length depends on what function code is. The value also represents by ASCII code.

LRC is simply sum of ASCII value started with destination address....to the LRC (00) without carry flag, and make two's complement. It will be used to check the integrity of the received frame.

CR and LF is frame terminator, 0x0d and 0x0a.

Let the master address is 02 and slave is 10. The slave can read analog signal from pyranometer. The value for insolation is 753W/m^2. Slave will save the digital value in register number 01. Suppose the master want to read data from slave. The master will send query frame as to read the content of register number 10 of slave address 10. Slave responses with frame that contains value of 753W/m^2 to the master.

Sample code for experimenting MODBUS protocol with 8051SBC.

Global network with Internet

 


Copyright (C) 2005 by Wichit Sirichote, kswichit@kmitl.ac.th
HOME BACK