Table of Contents

XnorSerial Communication Library:

Embedded devices library

Instantiate 'XnorSerial'object

  1. Include the library globally.
  2. Instantiate byte array variable. This is used as a shared memory for communication. Size of array is free to choose.
  3. Instantiate XnorSerial object, passing the HardwareSerial port by reference, followed by the previously instantiated byte array.
#include "XnorSerial.h"
byte bus_memory[4]; 
XnorSerial XS(&Serial1, bus_memory);
 
void setup()
{
   Serial1.begin(9600);
}
 
void serialEvent1(){XS.SerialEventProc();}  // Event handler for Serial1.
                                            // Edit Serial-number accordingly! XS.SerialEventProc(); can also be called inside a loop when interrupt based serial events are not supported. 
 
void loop(){...}

Example code above creates an bus_memory byte array that is 4 bytes long. All data stored inside this array is (read/write) accessible trough the Serial1 port.

Bugs:

None found up to this point.

Downloads


Host device

Protocol:

The serial host device (or master) has to send data following the correct protocol to read/write data from the embedded device. The data to send exists out of minimum 2 bytes, for a read request. More than 2 bytes defaults to a write request.

Each communication must start with a SOH ascii byte (0x01), this byte can be send in conjunction with additional byte-data or as a separated byte. After sending the SOH-byte the embedded master device pauses all other operation for 2 seconds, if no data is received within those 2 seconds the communication will timeout and normal master operation will continue.

After receiving an SOH-byte the embedded device will reply an ACK ascii byte (0x06), to initiate communication has started. After completing communication the embedded device will end communication with an EOT ascii byte (0x04).

Read request:

To read data from the embedded device the host has to send an SOH-byte followed by 2 protocol bytes. Those 2 bytes configure the start index and amount of data we request from the embedded device'shared' byte array.

 Read requests





Write request:

 Write request

To write data to the embedded device, the host has to send an SOH-byte before sending 2 protocol bytes.
The last protocol byte is then followed by data bytes. The first 2 bytes keep the same logic as in read mode, following bytes are written to the 'shared' byte array.