-
Notifications
You must be signed in to change notification settings - Fork 4
Sensor PCB Communication
Communication between the Main PCB and Sensor PCB is register based, with a simple read/write API.
Pointer: there is a global pointer for read and write operations. Each read or write operation (1 byte) moves the pointer up by one byte, making it possible to read or write multiple consecutive bytes without addressing them explicitly one after the other. Data outside the table return 0 when read, and is ignored when written.
Read operation: The host sends one byte to position the pointer on the desired register, then performs as many read operations as needed.
Write operation: The host sends multiple bytes all at once. The first one is the position the pointer moves to, all the subsequent ones are the values to write to the registers, in ascending order.
WARNING : due to a limitation of the I2C lib used in the ATTiny of the Sensor PCB, write operations are not processed immediately. Instead, they are processed when a read operation is initiated. Therefor, to validate one or more consecutive write operations, a dummy read operation should be performed immediately afterwards.
CAUTION: Sensor values are not updated all the time. instead, you have to ask for an update by writing a non-zero value to REG_UPDATE (and validate it with a dummy read), the wait for the sensor update to happen (a millisecond should be enough) before reading the sensor registers.
The reference for the register table used is in the regs.h file. The values reported here are for convenience only.
REG_LEN 16 // number of bytes in memory
- REG_IDENTIFIER 0x00 // 1 byte (R) identifier used to test that the communication is OK. Only 100% fixed value across revisions and runs (see common.h).
- REG_VERSION 0x01 // 1 byte (R) code version, in case we need to update one day...
- REG_OSCCAL 0x02 // 1 byte (RW) value of OSCCAL register
- REG_TEMP 0x03 // 2 bytes (R) [NOT IMPLEMENTED YET] ADC value (10 bits) of internal temp sensor. See MCU datasheet for interpretation.
- REG_MQ135 0x05 // 2 bytes (R) voltage value of the MQ-135 in mV, assuming power is 5.00V
- REG_HEATER_ON 0x07 // 1 byte (RW) state of the controlled heaters. 0 is OFF, any other value is ON. Default: 0
- REG_NB_SAMPLES 0x08 // 1 byte (RW) number of samples the sensors value are computed on.
- REG_UPDATE 0x09 // 1 byte (RW) write anything non-zero to trigger an update of the sensors and temp values (cleared when completed).