Mikroelektronika MIKROE-350 データシート

ページ / 526
RS485Slave_Send
Library Example
This is a simple demonstration of RS485 Library routines usage.
Master sends message to Slave with address 160 and waits for a response. The Slave accepts
data, increments it and sends it back to the Master. Master then does the same and sends incre-
mented data back to Slave, etc.
Master displays received data on P0, while error on receive (0xAA) and number of consecutive
unsuccessful retries are displayed on P1. Slave displays received data on P0, while error on
receive (0xAA) is displayed on P1. Hardware configurations in this example are made for the
EasyAVR5A board and ATmega16.
RS485 Master code:
332
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub procedure RS485Slave_Send(dim byref data_buffer as byte[20],
dim datalen as byte)
Returns
Nothing.
Description
Sends message to Master. Message format can be found at the bottom of this
page.
Parameters : 
data_buffer:
data to be sent 
datalen:
number of bytes for transmition. Valid values: 0...3. 
Requires
MCU must be initialized as a Slave for RS-485 communication. See
RS485Slave_Init. It is the user’s responsibility to ensure (by protocol) that only
one device sends data via 485 bus at a time.
Example
dim msg as byte[8]
...
' send 2 bytes of data to the master
RS485Slave_Send(msg, 2)