# Firmware for controllers of thermal sensors

Make regular scan of 8 sensors' pairs.
USART speed 115200. Code for ../../kicad/stm32

### Serial interface commands (ends with '\n'), small letter for only local processing:
- **1...7** - send message to Nth controller, not broadcast (after number should be CAN command)
- **B** send dummy CAN messages to broadcast address
- **c** show coefficients for all thermosensors
- **D** send dummy CAN messages to master (0) address
- **Ee** end temperature scan
- **Ff** turn sensors off
- **g** get last CAN address
- **Hh** switch I2C to high speed (100kHz)
- **i** reinit CAN
- **Ll** switch I2C to low speed (default, 10kHz)
- **P** ping everyone over CAN
- **Rr** reinit I2C
- **Ss** start temperature scan
- **Tt** start single temperature measurement
- **u** check CAN bus status for errors
- **Vv** very low speed
- **Z** get sensors state over CAN

### PINOUT
- I2C: PB6 (SCL) & PB7 (SDA)
- USART1: PA9 (Tx) & PA10 (Rx)
- CAN bus: PB8 (Rx), PB9 (Tx)
- USB bus: PA11 (DM), PA12 (DP)
- I2C multiplexer: PB0..PB2 (0..2 address bits), PB12 (~EN)
- sensors' power: PB3 (in, overcurrent), PA8 (out, enable power)
- signal LEDs: PB10 (LED0), PB11 (LED1)
- ADC inputs: PA0 (V12/4.93), PA1 (V5/2), PA3 (I12 - 1V/A), PA6 (V3.3/2)
- controller CAN address: PA13..PA15 (0..2 bits); 0 - master, other address - slave


### LEDS
- LED0 (nearest to sensors' connectors) - heartbeat
- LED1 (above LED0) - CAN bus OK

### CAN protocol
Variable data length: from 1 to 7 bytes.
First byte of every sequence is command mark (0xA5) or data mark (0x5A).

Commands:
- CMD_PING - send from master to receive answer in data packet if target alive.
- CMD_START_MEASUREMENT - start single temperature measurement.
- CMD_SENSORS_STATE - state of sensors.

Data format:
- 1 byte - Controller number
- 2 byte - Command received
- 3..7 bytes - data

Thermal data format:
- 3 byte - Sensor number (10*N + M, where N is multiplexer number, M - number of sensor in pair, i.e. 0,1,10,11,20,21...70,71)
- 4 byte - thermal data H
- 5 byte - thermal data L

