From f94d9153285c47b2c356547961003c108e43cb00 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 1 Sep 2019 23:56:45 +0200 Subject: [PATCH] identify adc --- firmware/src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/firmware/src/main.rs b/firmware/src/main.rs index 91c4a73..99c95f2 100644 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -107,13 +107,26 @@ fn main() -> ! { let pe4 = board::gpio::PE4.into_output(); // MISO let pe5 = board::gpio::PE5.into_input(); + // max 2 MHz = 0.5 us let mut delay_fn = || delay.delay_us(1u32); let spi = board::softspi::SyncSoftSpi::new( board::softspi::SoftSpi::new(pb5, pe4, pe5), &mut delay_fn ); let mut adc = ad7172::Adc::new(spi, pb4).unwrap(); - + loop { + let r = adc.identify(); + match r { + None => + writeln!(stdout, "Cannot identify ADC!").unwrap(), + Some(id) if id & 0xFFF0 == 0x00D0 => { + writeln!(stdout, "ADC id: {:04X}", id); + break; + } + Some(id) => + writeln!(stdout, "Corrupt ADC id: {:04X}", id).unwrap(), + }; + } let mut hardware_addr = EthernetAddress(board::get_mac_address()); if hardware_addr.is_multicast() { println!("programmed MAC address is invalid, using default");