Mikroelektronika MIKROE-738 Datenbogen
mikroC PRO for PIC32
MikroElektronika
407
RS485Master_Receive
RS485Master_Send
Prototype
void RS485Master_Receive(char *data_buffer);
Description Receives messages from Slaves. Messages are multi-byte, so this routine must be called for each
byte received.
Parameters -
data_buffer
: 7 byte buffer for storing received data. Data will be stored in the following manner:
-
data_buffer[0..2]
: message content
-
data_buffer[3]
: number of message bytes received, 1–3
-
data_buffer[4]
: is set to 255 when message is received
-
data_buffer[5]
: is set to 255 if error has occurred
-
data_buffer[6]
: address of the Slave which sent the message
The routine automatically adjusts
data[4]
and
data[5]
upon every received message. These flags
need to be cleared by software.
Returns
Nothing.
Requires
MCU must be initialized as a Master for RS-485 communication. See RS485Master_Init.
Example
char msg[8];
...
RS485Master_Receive(msg);
Notes
None
Prototype
void RS485Master_Send(char *data_buffer, char datalen, char slave_
address);
Description Sends message to Slave(s). Message format can be found at the bottom of this page.
Parameters -
Parameters -
data_buffer
: data to be sent
-
datalen
: number of bytes for transmition. Valid values: 0...3.
-
slave_address
: Slave(s) address
Returns
Nothing.
Requires
MCU must be initialized as a Master for RS-485 communication. See RS485Master_Init.
It is the user’s responsibility to ensure (by protocol) that only one device sends data via 485 bus at a
time.
Example
char msg[8];
...
// send 3 bytes of data to Slave with address 0x12
RS485Master_Send(msg, 3, 0x12);
Notes
None