Crate tcn75a[−][src]
Expand description
tcn75a
is an Embedded HAL crate for accessing Microchip TCN75A temperature
sensors over an I2C bus.
The TCN75A consists of 4 registers and a writeable register pointer. Three registers are for configuration, represented as the following:
- Sensor Configuration Register (various
enum
s) - Temperature Hysteresis Register (
FixedI16::<U8>
(I8F8
), -128.0 to 127.5, 0.5 degrees Celsius resolution) - Temperature Limit-Set Register (
FixedI16::<U8>
(I8F8
), -128.0 to 127.5, 0.5 degrees Celsius resolution)
The remaining register contains the current temperature as an FixedI16::<U8>
(I8F8
),
from -128.0 to 127.9375 (variable increments based on Resolution
).
To avoid redundant register reads and write, the tcn75a
crate caches the contents of some
registers (particularly the register pointer and Sensor Configuration Register). At present,
the tcn75a
crate therefore only works on I2C buses with a single controller. Multi-controller
operation is possible at the cost of performance, but not implemented.
Examples
use eyre::eyre; use fixed::types::I8F8; use linux_embedded_hal::I2cdev; use std::error::Error; use tcn75a::{Tcn75a, ConfigReg, Resolution}; fn main() -> Result<(), Box<dyn Error>> { let i2c = I2cdev::new("/dev/i2c-1")?; let mut tcn = Tcn75a::new(i2c, 0x48); let mut cfg = ConfigReg::new(); cfg.set_resolution(Resolution::Bits12); tcn.set_config_reg(cfg) .map_err(|_e| eyre!("failed to set config reg"))?; let temp = tcn.temperature().map_err(|_e| eyre!("failed to read a temperature"))?; println!("Temperature is {:^7} C.", I8F8::from(temp)); Ok(()) }
Structs
ConfigReg | Representation of the Sensor Configuration Register. |
ConfigRegValueError | Error type due to failed conversions from u8 into Configuration Register fields. |
Limits | A struct representing the Hysteresis and Limit-Set registers of the TCN75A. |
Tcn75a | A struct for describing how to read and write a TCN75A temperature sensors’ registers via an
|
Temperature | A struct representing a temperature reading from the TCN75A. |
Enums
AlertPolarity | Alert Polarity bit in the Sensor Configuration Register. |
CompInt | Comp/Int bit in the Sensor Configuration Register. |
FaultQueue | Fault Queue bits in the Sensor Configuration Register. |
LimitError | Reasons a conversion from |
OneShot | One-Shot bit in the Sensor Configuration Register. |
Resolution | ADC Resolution bits in the Sensor Configuration Register. |
Shutdown | Shutdown bit in the Sensor Configuration Register. |
Tcn75aError | Enum for describing possible error conditions when reading/writing a TCN75A temperature sensor. |
Type Definitions
Error | Convenience type for representing |