5 unstable releases

0.3.0 Feb 18, 2024
0.2.2 Feb 11, 2024
0.2.1 Feb 7, 2024
0.2.0 Feb 7, 2024
0.1.0 Feb 4, 2024

#503 in Embedded development

Download history 3/week @ 2024-02-07 109/week @ 2024-02-14 26/week @ 2024-02-21 5/week @ 2024-02-28 1/week @ 2024-03-06 2/week @ 2024-03-13

51 downloads per month

MIT license

27KB
504 lines

Driver for Analog Devices AD57xx series of dual and quad channel 16/14/12bit DACs

crates.io Docs

Compatibility has only been tested with the AD5754. However the only difference between the different chips is the channel count and the bit-depth. Readback operation is currently untested as my hardware does not support it. If you are in the opportunity to do so please let me know your findings.

Any contribution to this crate is welcome, as it's my first published crate any feedback is appreciated.

To-do:

  • Register definitions
  • Write functionality for all registers
  • Minimal working example with a shared bus on stm32f4xx
  • Dual channel chip support (untested)
  • #[tests] on target
  • Testing readback functionality
  • Exclusive device struct
  • Support daisy-chain operation
  • Async support

Usage example

// Setup the DAC's SPI bus and SYNC pin
let gpioc = p.GPIOC.split();
let spi3_sclk = gpioc.pc10.into_alternate();
let spi3_miso = gpioc.pc11.into_alternate();
let spi3_mosi = gpioc.pc12.into_alternate();
// We are using the ~SYNC pin as CS with ~LDAC tied to ground this puts
// the device in individual update mode, loading the dac register on each
// write operation
let gpioa = p.GPIOA.split();
let spi3_dac_sync = gpioa
    .pa15
    .into_push_pull_output_in_state(hal::gpio::PinState::High);
// SPI Instance initialization in MODE 2
let spi3 = Spi::new(
    p.SPI3,
    (spi3_sclk, spi3_miso, spi3_mosi),
    Mode {
            phase: hal::spi::Phase::CaptureOnFirstTransition,
            polarity: hal::spi::Polarity::IdleHigh,
    },
    1.MHz(),
    &ccdr,
);
// SPI Bus creation using embedded-hal-bus
let spi_bus = RefCell::new(spi3);

// Creating shared DAC SPI Device
let mut dac = Ad57xxShared::new_ad57x4(RefCellDevice::new(&spi_bus, spi3_dac_sync, NoDelay));

// Setup the DAC as desired.
dac.set_power(ad57xx::ad57x4::Channel::AllDacs, true).unwrap();
dac.set_output_range(ad57xx::ad57x4::Channel::AllDacs, ad57xx::OutputRange::Bipolar5V)
    .unwrap();
// Output a value (left-aligned 16 bit)
dac.set_dac_output(ad57xx::ad57x4::Channel::DacA, 0x9000).unwrap();

Dependencies

~0.7–1.2MB
~25K SLoC