From feae22b277e62fdeae54aa1f42206e86e2a44c9e Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 16 May 2020 01:18:14 +0200 Subject: [PATCH] ad5680: idle low for powersaving --- src/ad5680.rs | 11 +++++++---- src/main.rs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ad5680.rs b/src/ad5680.rs index cc75c95..f550777 100644 --- a/src/ad5680.rs +++ b/src/ad5680.rs @@ -25,7 +25,7 @@ pub struct Dac, S: OutputPin> { impl, S: OutputPin> Dac { pub fn new(spi: SPI, mut sync: S) -> Self { - let _ = sync.set_high(); + let _ = sync.set_low(); Dac { spi, @@ -34,11 +34,14 @@ impl, S: OutputPin> Dac { } fn write(&mut self, mut buf: [u8; 3]) -> Result<(), SPI::Error> { - let _ = self.sync.set_low(); - let result = self.spi.transfer(&mut buf); + // pulse sync to start a new transfer. leave sync idle low + // afterwards to save power as recommended per datasheet. let _ = self.sync.set_high(); + cortex_m::asm::nop(); + let _ = self.sync.set_low(); - result.map(|_| ()) + self.spi.transfer(&mut buf)?; + Ok(()) } /// value: `0..0x20_000` diff --git a/src/main.rs b/src/main.rs index 06a377c..07e4b92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -144,7 +144,7 @@ fn main() -> ! { let ref_adc_data = channels.read_ref_adc(channel); let state = channels.channel_state(channel); let _ = writeln!( - socket, "t={} raw{}=0x{:06X} ref_adc={}", + socket, "t={} raw{}=0x{:06X} ref_adc=0x{:X}", state.adc_time, channel, adc_data, ref_adc_data );