Crate mcp3x6x

Crate mcp3x6x 

Source
Expand description

no_std library for the MCP3x6x(R) family of analog digital converters.

Supports:

  • MCP3461
  • MCP3462
  • MCP3464
  • MCP3561
  • MCP3562
  • MCP3564
  • MCP3461R
  • MCP3462R
  • MCP3464R
  • MCP3465R
  • MCP3561R
  • MCP3562R
  • MCP3564R
  • MCP3565R

§Features:

  • Activate one of the device features to enable support for the corresponding device.
  • defmt feature implements defmt::Format for all registers.

§Basic usage:

use mcp3x6x::{ClkSel, Config0, FastCommand, Irq, MCP3x6x, ToVoltageConverter24bit};

// use 3.3V as Vref+ and 0V as Vref-
const TO_VOLT: ToVoltageConverter24bit = ToVoltageConverter24bit::new(3.3, 0.0, mcp3x6x::Gain::X1);

// spi is a struct implementing embedded_hal::spi::SpiDevice.
// irq is an input pin attached to the IRQ pin of the ADC.

let mut adc = MCP3x6x::new(spi);

// use internal clock
let config0 = Config0::default().with_clk_sel(ClkSel::InternalClock);
adc.write_register(config0).unwrap();

// disable en_stp
let irq = Irq::default().with_en_stp(false);
adc.write_register(irq).unwrap();

// be ready for conversions
adc.fast_command(FastCommand::Standby).unwrap();

loop {
    adc.fast_command(FastCommand::ConversionStart);
    while irq_pin.is_high() {}
    let sample = adc.read_24_bit_adc_data().unwrap();
    let voltage = TO_VOLT.to_volt(sample);
}

Structs§

Config0
ADC Operating mode, Master Clock mode and Input Bias Current Source mode
Config1
Prescale and OSR settings
Config2
ADC boost and gain settings, auto-zeroing settings for analog multiplexer, voltage reference and ADC
Config3
Conversion mode, data and CRC format settings; enable for CRC on communications, enable for digital offset and gain error calibrations
GainCal
Gain Error Digital Calibration Code The GAINCAL default value is 0x800000, which provides a gain of 1x.
Irq
IRQ Status bits and IRQ mode settings; enable for Fast commands and for conversion start pulse
MCP3x6x
MCP3x6x(R) Analog Digital Converter
Mux
Analog multiplexer input selection (MUX mode only)
OffsetCal
Offset Error Digital Calibration Code
Scan
SCAN mode settings
StatusByte
The three Interrupt Status bits are independent of the two other interrupt mechanisms (IRQ pin and IRQ register) and are cleared each time the STATUS byte is fully clocked.
Timer
Selection Bits for the Time Interval (TTIMER_SCAN) Between Two Consecutive SCAN Cycles CONV_MODE = 1
ToVoltageConverter16bit
Helper struct for convertion an adc reading to a voltage.
ToVoltageConverter24bit
Helper struct for convertion an adc reading to a voltage.

Enums§

AdcMode
ADC Operating Mode Selection
Boost
ADC Bias Current Selection
ClkSel
Clock Selection
ConvMode
Conversion Mode Selection
CrcFormat
CRC Checksum Format Selection on Read Communications
CsSel
Current Source/Sink Selection Bits for Sensor Bias (source on VIN+/sink on VIN-
DataFormat
ADC Output Data Format Selection
Dly
Delay Time Between Each Conversion During SCAN Cycle
FastCommand
Fast command
Gain
ADC Gain Selection
Lock
Password value for SPI Write mode locking
MuxInput
MUX_VIN Input Selection
Osr
Oversampling Ratio for Delta-Sigma A/D Conversion
Pre
Prescaler Value Selection for AMCLK
RegisterAddress
Available registers

Traits§

Register
Register
WriteableRegister
Writeable Register