identify adc

This commit is contained in:
Astro 2019-09-01 23:56:45 +02:00
parent ea395460c8
commit f94d915328

View File

@ -107,13 +107,26 @@ fn main() -> ! {
let pe4 = board::gpio::PE4.into_output(); let pe4 = board::gpio::PE4.into_output();
// MISO // MISO
let pe5 = board::gpio::PE5.into_input(); let pe5 = board::gpio::PE5.into_input();
// max 2 MHz = 0.5 us
let mut delay_fn = || delay.delay_us(1u32); let mut delay_fn = || delay.delay_us(1u32);
let spi = board::softspi::SyncSoftSpi::new( let spi = board::softspi::SyncSoftSpi::new(
board::softspi::SoftSpi::new(pb5, pe4, pe5), board::softspi::SoftSpi::new(pb5, pe4, pe5),
&mut delay_fn &mut delay_fn
); );
let mut adc = ad7172::Adc::new(spi, pb4).unwrap(); 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()); let mut hardware_addr = EthernetAddress(board::get_mac_address());
if hardware_addr.is_multicast() { if hardware_addr.is_multicast() {
println!("programmed MAC address is invalid, using default"); println!("programmed MAC address is invalid, using default");