Hello, I've found a strange error and I'm not sure what the problem might be. I've been trying to use ESP32 + SCD41 with no luck. I tracked down the problem to this piece of code:
// source https://github.com/Sensirion/sensirion-i2c-rs/blob/master/src/crc8.rs#L11-L25
pub fn calculate(data: &[u8]) -> u8 {
const CRC8_POLYNOMIAL: u8 = 0x31;
let mut crc: u8 = 0xff;
for byte in data {
crc ^= byte;
for _ in 0..8 {
if (crc & 0x80) > 0 {
crc = (crc << 1) ^ CRC8_POLYNOMIAL;
} else {
crc <<= 1;
}
}
}
crc
}
For the given example data [9, 94] the correct result should be 35 but I'm getting 55. It works correctly on the blank Rust project using cargo new but it fails when I deploy the code to my ESP32.
I've created an example here https://wokwi.com/projects/345876589283639891 with 2 identical calculate functions, the only difference is that one of them has println! macros inside. However, the result differs.
Does anyone know what's going on? What am I missing?
Hello, I've found a strange error and I'm not sure what the problem might be. I've been trying to use ESP32 + SCD41 with no luck. I tracked down the problem to this piece of code:
For the given example data
[9, 94]
the correct result should be35
but I'm getting55
. It works correctly on the blank Rust project usingcargo new
but it fails when I deploy the code to my ESP32.I've created an example here https://wokwi.com/projects/345876589283639891 with 2 identical
calculate
functions, the only difference is that one of them hasprintln!
macros inside. However, the result differs.Does anyone know what's going on? What am I missing?