| Crates.io | mcp3x6x |
| lib.rs | mcp3x6x |
| version | 0.3.1 |
| created_at | 2025-12-02 19:22:13.659093+00 |
| updated_at | 2026-01-20 12:16:08.797418+00 |
| description | no_std library for the MCP3x6x(R) family of analog digital converters |
| homepage | |
| repository | https://github.com/WMT-GmbH/mcp3x6x |
| max_upload_size | |
| id | 1962460 |
| size | 56,738 |
no_std library for the MCP3x6x(R) family of analog digital converters.
Supports:
defmt feature implements defmt::Format for all registers.use mcp3x6x::{FastCommand, MCP3x6x, ToVoltageConverter24bit, Irq, ClkSel, Config0};
// 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);
}