Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve temperature reading #50

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/all/i2c_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ static void read_temperature_sensor_value(Mmio<OpenTitanI2c> i2c,
i2c->blocking_write(0x48, buf, 1, false);
if (i2c->blocking_read(0x48, buf, 2u))
{
uint16_t temp = (buf[0] << 8) | buf[1];
Debug::log("The {} readout is {}", regName, temp);
int16_t regValue = static_cast<int16_t>((buf[0] << 8) | buf[1]);
int64_t temp = regValue * 1000000LL / 128;
Debug::log("The {} readout is {} microdegrees Celcius", regName, temp);
}
else
{
Expand Down