LibRS485 uses a 9bit protocol and Multi-processor Communication mode defined in ATmega. This allows the MCU to do other thing without looking on communication unless there is a address frame. Basically i work like this:
- All nodes are in Multi-processor Communication mode (MPCM)
- One of the node sends an address frame, and all receive and read this frame.
- All nodes reads the address frame and determine if it has been selected. If so, it clears the MPCM, otherwise it waits for the next address frame and
keeps the MPCM setting.
- The addressed node will receive all data frames until a new address frame is received.
- The other nodes which still have the MPCM bit set, will ignore the data frames.
- When the last data frame is received by the addressed node, the addressed MCU sets the MPCM and waits for a new address frame. The process then
repeats from 2.
-------------~~~~~~~~~~~~~~~~~~~~~~ - A - P - X - D0 - D63 ~ S0 ~ S1 ~ -------------~~~~~~~~~~~~~~~~~~~~~~ - Required fields ~ Data and signature fields A Address - 4 bits form and 4 bits to address. 0 is master, but not really as any node can drive communication 15 is broadcast to all 14 addresses left for other devices P Packet definition - 2 bits type and 6 bits length. Flag bit configuration: FLAG_ACK 3 FLAG_NAK 2 FLAG_CMD 1 FLAG_DTA 0 Types: CMD - Command - user defined general commands value 0 - 63 DTA - Data - user data length D0 - D63 and CRC S0, S1 ACK, NAK - flags for data, using signature of data packet X XOR of A and P, for basic transfer safety. D0 - D63 user data. S0 ~ S0 CRC for user data or signature for ACK, NAK.
So basically there are two types of packets. Command packet that has only 3 bytes (APX) and deliver a command(number 0-63) to node(s). It is used for example to issue a call for registration. Or data packet that has 6-69 bytes (APX D0~D63 S0S1). This deliver any data to node(s). The nodes are addressed by its address 0-14, which select any individual node. Or address 15 that is broadcast to all nodes.