The original set of modules for Apex III did not support I2C (as they were based upon the PICAXE 08M2). As a result a serial protocol for communications between modules was created.
The protocol between the Core and the Modules is fairly simple. Each board – including the core – has an address. These are defined in the
protocol.h file. Below is a list of the addresses which is correct at the time of posting (21 Feb 2012).
Broadcast = 0x00 Core = 0x01 Siren and Cutdown = 0x02 Light (R & G) = 0x03 Pressure = 0x04 Camera Tilt = 0x05 Analog to Digital = 0x06 Gas = 0x07 Radiation A = 0x08 Radiation B = 0x09 Light (B & Normal) = 0x0A
The protocol is formed of 7 bytes in total; together these are known as the packet. Both the Core and the Modules will send out a null byte before beginning the transmission of a packet. A typical packet looks like this:
| BYTE 0 | BYTE 1 | BYTE 2 | BYTE 3 | BYTE 4 | BYTE 5 | BYTE 6 | | 0x23 (#) | Sender's Address | 0x2B (+) | Data Byte 0 | Data Byte 1 | Data Byte 2 | Data Byte 3 |
Core to Module Messages
The Core will always initiate any request to a module. A module will never send out a message unless requested to do so by the core. At the beginning of every loop to form a new sentence the core will send out a message to the Broadcast address (0x00), this is a message to all modules to begin taking measurements as they will be asked for their data soon. The Core will then take measurements from it’s own sensors and read in the GPS data before requesting data from every module. This should leave enough time for a module to complete its readings. A typical request from the Core looks like this:
| BYTE 0 | BYTE 1 | BYTE 2 | BYTE 3 | BYTE 4 | BYTE 5 | BYTE 6 | | 0x23 (#) | 0x01 (Core Addr) | 0x2B (+) | Module Address | Command | Altitude (LSB) | Altitude (MSB) |
The command and the altitude can be ignored by most modules, however the cutdown, siren and camera tilt systems will require this data.
None = 0x00 Ping = 0x01 Cutdown = 0x02 Siren Off = 0x03 Siren On = 0x04 Altitude Reset = 0x05
When the Destination/Module Address requested by the Core is 0x00 (the Broadcast Address), the Module should take a measurement. However, when the address matches the Module’s own address, the module must reply with 7 bytes of data; 4 of which should be sensor data. A reply looks like this:
| BYTE 0 | BYTE 1 | BYTE 2 | BYTE 3 | BYTE 4 | BYTE 5 | BYTE 6 | | 0x23 (#) | Module's Address | 0x2B (+) | Data Byte 0 | Data Byte 1 | Data Byte 2 | Data Byte 3 |
If a data byte is not required, 0x00 should be transmitted. For example, if only one reading, between 0 and 255, is needed from a module, Data Bytes 1 to 3 should be 0x00.
Implementation of the Protocol
The Core side of the protocol is implemented in C and can be found in the files:
protocol.h. The Module side of the protocol is implemented in PICAXE BASIC and a copy of the latest framework can be found on the following page: https://github.com/ApexHAB/apex-iii/blob/master/modules/module_framework.bas. All modules should utilise this framework and code should only be inserted into the commented areas.