I have some code to try and read from the Temperature I2C, which is obtaining values but these do not make sense, nor are they changing over time.
The data also fails the CRC check, further suggesting what is coming back isn't valid.
Does anyone have any working examples of being able to read from the temperature sensor?
Our code:
#define SHT31_ADDRESS (0x44 << 1)
i2cFd = I2CMaster_Open(MT3620_RDB_HEADER2_ISU0_I2C);
void SendTempTelemetry(void)
{
char telemetryBufferTemp[TELEMETRY_BUFFER_SIZE];
char telemetryBufferHum[TELEMETRY_BUFFER_SIZE];
uint8_t readData[6];
I2CMaster_Read(i2cFd, SHT31_ADDRESS, readData, sizeof(readData));
if (readData[2] != CalcCRC8(&readData[0], 2))
Log_Debug("ERROR: temperature CRC failed.\n");
if (readData[5] != CalcCRC8(&readData[3], 2))
Log_Debug("ERROR: humidity CRC failed.\n");
uint16_t ST;
ST = readData[0];
ST = (uint16_t)(ST << 8);
ST = (uint16_t)(ST | readData[1]);
uint16_t SRH;
SRH = readData[3];
SRH = (uint16_t)(SRH << 8);
SRH = (uint16_t)(SRH | readData[4]);
float Temperature = NAN;
float Humidity = NAN;
Temperature = (float)ST * 175 / 0xffff - 45;
Humidity = (float)SRH * 100 / 0xffff;
int len0 = snprintf(telemetryBufferTemp, TELEMETRY_BUFFER_SIZE, "{\"Temperature\":%3.2f}", Temperature);
if (len0 < 0 || len0 >= TELEMETRY_BUFFER_SIZE) {
Log_Debug("ERROR: Cannot write temp telemetry to buffer.\n");
return;
}
int len1 = snprintf(telemetryBufferHum, TELEMETRY_BUFFER_SIZE, "{\"Humidity\":%3.2f}", Humidity);
if (len1 < 0 || len1 >= TELEMETRY_BUFFER_SIZE) {
Log_Debug("ERROR: Cannot write hum telemetry to buffer.\n");
return;
}
SendTelemetry(telemetryBufferTemp);
SendTelemetry(telemetryBufferHum);
}
In general temperature is always returning 124, and humidity 74 without any variation over time.