User`s manual
RS485 is a multipoint communication which allows multiple devices to be con-
nected to a single signal cable. mikroBasic provides a set of library routines to
provide you comfortable work with RS485 system using Master/Slave architec-
ture.
Master and Slave devices interchange packets of information, each of these pack-
ets containing synchronization bytes, CRC byte, address byte, and the data. In
Master/Slave architecture, Slave can never initiate communication. Each Slave has
its unique address and receives only the packets containing that particular address.
It is programmer's responsibility to ensure that only one device transmits data via
485 bus at a time.
Address 50 is a common address for all Slave devices: packets containing address
50 will be received by all Slaves. The only exceptions are Slaves with addresses
150 and 169, which require their particular address to be specified in the packet.
RS485 routines require USART module on port C. Pins of USART need to be
attached to RS485 interface transceiver, such as LTC485 or similar. Pins of trans-
ceiver (Receiver Output Enable and Driver Outputs Enable) should be connected
to port C, pin 2 (see the figure at end of the chapter).
Following routines implement flexible protocol for RS485 system with
Master/Slave architecture:
mikroBASIC
- Basic Compiler for Microchip PIC microcontrollers
150
mikroBASIC
MikroElektronika: Development tools - Books - Compilers
making it simple...
page
RS485 Library
sub procedure RS485master_init
sub procedure RS485slave_init(dim address as byte)
sub procedure RS485master_read(dim byref data as byte[5])
sub procedure RS485master_write(dim byref data as byte[2],
dim datalen as byte, dim address as byte)
sub procedure RS485slave_read(dim byref data as byte[5])
sub procedure RS485slave_write(dim byref data as byte[2],
dim datalen as byte)
Routines
Note