Crate lm73

source ·
Expand description

This is a platform agnostic Rust driver for the lm73 temperature sensor and thermal watchdog, based on the embedded-hal traits.

This driver allows you to:

  • Enable/disable the device.
  • Read the temperature.
  • Set the fault queue.
  • Set the OS temperature.
  • Set the hysteresis temperature.
  • Set the OS operation mode.
  • Set the OS polarity.

The device

The lm73 temperature sensor includes a delta-sigma analog-to-digital converter, and a digital overtemperature detector. The host can query the lm73 through its I2C interface to read temperature at any time. The open-drain overtemperature output (OS) sinks current when the programmable temperature limit is exceeded. The OS output operates in either of two modes, comparator or interrupt. The host controls the temperature at which the alarm is asserted (TOS) and the hysteresis temperature below which the alarm condition is not valid (THYST). Also, the lm73’s TOS and THYST registers can be read by the host. The address of the lm73 is set with three pins to allow multiple devices to work on the same bus. Power-up is in comparator mode, with defaults of TOS= +80ºC and THYST= +73ºC. The 3.0V to 5.5V supply voltage range, low supply current, and I2C interface make the lm73 ideal for many applications in thermal management and protection.

Datasheet:

This driver is also compatible with at least lm73A, lm73B, lm73C, AT30TS73A, DS1773, DS73, DS7305, G731, MAX7300/1/2/3/4, MAX6625, MCP9800/1/2/3, STDS73, TCN73.

Usage examples (see also examples folder)

To use this driver, import this crate and an embedded_hal implementation, then instantiate the device.

Please find additional examples in this repository: lm73-examples

Read temperature

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let address = SlaveAddr::default();
let mut sensor = lm73::new(dev, address);
let temp_celsius = sensor.read_temperature().unwrap();
println!("Temperature: {}ºC", temp_celsius);

Provide an alternative address

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let (a2, a1, a0) = (false, false, true);
let address = SlaveAddr::Alternative(a2, a1, a0);
let mut sensor = lm73::new(dev, address);

Set the fault queue

This is the number of consecutive faults necessary to trigger an OS condition.

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr, FaultQueue };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = lm73::new(dev, SlaveAddr::default());
sensor.set_fault_queue(FaultQueue::_4).unwrap();

Set the OS polarity

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr, OsPolarity };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = lm73::new(dev, SlaveAddr::default());
sensor.set_os_polarity(OsPolarity::ActiveHigh).unwrap();

Set the OS operation mode

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr, OsMode };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = lm73::new(dev, SlaveAddr::default());
sensor.set_os_mode(OsMode::Interrupt).unwrap();

Set the OS temperature

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = lm73::new(dev, SlaveAddr::default());
let temp_celsius = 50.0;
sensor.set_os_temperature(temp_celsius).unwrap();

Set the hysteresis temperature

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = lm73::new(dev, SlaveAddr::default());
let temp_celsius = 40.0;
sensor.set_hysteresis_temperature(temp_celsius).unwrap();

Enable / disable the sensor

extern crate linux_embedded_hal as hal;
extern crate lm73;

use hal::I2cdev;
use lm73::{ lm73, SlaveAddr };

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut sensor = lm73::new(dev, SlaveAddr::default());
sensor.disable().unwrap(); // shutdown
sensor.enable().unwrap();

Structs

Lm73 device driver.

Enums

Alert Enable operation mode
All possible errors in this crate
OneShot operation mode
OS polarity
Resolution of temperature
Possible slave addresses