Datasheet

RS-485 LIBRARY
RS-485 is a multipoint communication which allows multiple devices to be connect-
ed to a single bus. The mikroC PRO for AVR provides a set of library routines for
comfortable work with RS485 system using Master/Slave architecture. Master and
Slave devices interchange packets of information. Each of these packets contains
synchronization bytes, CRC byte, address byte and the data. Each Slave has
unique address and receives only packets addressed to it. The Slave can never ini-
tiate communication.
It is the user’s responsibility to ensure that only one device transmits via 485 bus at
a time.
The RS-485 routines require the UART module. Pins of UART need to be attached
to RS-485 interface transceiver, such as LTC485 or similar (see schematic at the
bottom of this page).
Library constants:
- START byte value
= 150
- STOP byte value = 169
- Address 50 is the broadcast address for all Slaves (packets containing
address 50 will be received by all Slaves except the Slaves with
addresses 150 and 169).
Note:
- Prior to calling any of this library routines, UART_Wr_Ptr needs to be ini-
tialized with the appropriate UART_Write routine.
- Prior to calling any of this library routines, UART_Rd_Ptr needs to be ini-
tialized with the appropriate UART_Read routine.
- Prior to calling any of this library routines, UART_Rdy_Ptr needs to be ini-
tialized with the appropriate UART_Ready routine.
- Prior to calling any of this library routines, UART_TX_Idle_Ptr needs to be
initialized with the appropriate UART_TX_Idle routine.
External dependencies of RS-485 Library
390
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6
The following variable
must be defined in all
projects using RS-485
Library:
Description: Example :
extern sfr sbit
RS485_rxtx_pin;
Control RS-485 Trans-
mit/Receive operation
mode
sbit RS485_rxtx_pin
at PORTD.B2;
extern sfr sbit
RS485_rxtx_pin_direc-
tion;
Direction of the RS-485
Transmit/Receive pin
sbit
RS485_rxtx_pin_direc-
tion at DDRD.B2;