USB interface for ADT7422 temperature sensor based on STM32F4 board by WeAct.
- PB6 - I2C Data
- PB7 - I2C Clock
The board send temperature readings over Virtual COM-port every second. The data is being send in the following format:
Byte 1 | Byte 2 | Byte 3 | Byte 4 |
---|---|---|---|
Temp MSB | Temp LSB | CRC8 | CR ('\r') |
Where CRC8 is calculated by:
uint8_t CRC8(const uint8_t *data, size_t length) {
uint8_t crc = 0;
for (size_t i = 0; i < length; ++i) {
crc ^= data[i];
for (int j = 0; j < 8; ++j) {
if (crc & 0x80) {
crc = (crc << 1) ^ 0x07; // Polynomial 0x07
} else {
crc <<= 1;
}
}
}
return crc;
}
Use the following formulas to calculate the measured temperatures in °C from the ADT7422 output codes in 16-bit format (where ADC Code uses all 16 bits of the data byte, including the sign bit):
Positive Temperature = ADC Code (Decimal)/128
Negative Temperature = (ADC Code (Decimal) − 65,536)/128
Where Bit 15 (sign bit) is removed from the ADC code:
Negative Temperature = (ADC Code (Decimal) − 32,768)/128
Project can be built in Visual Studio Code with C/C++ and STM32 plugins installed.
To build and debug ARM Embedded Toolchain and OpenOCD are both required.