diff --git a/src/main.rs b/src/main.rs index 32e1ce2..f1aea66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,13 +151,18 @@ fn main() -> ! { w.moder15().output() }); - // Configure push-button as input; + // Configure push-button (PA0) as input; // Configure PA1 as analog-in per.gpioa.moder.modify(|_, w| { w.moder0().input() .moder1().analog() }); + // Clear PA3. PA3 can then be a ground reference point for the piezo. + // per.gpioa.odr.write(|w| { + // w.odr3().clear_bit() + // }); + // Configure piezo as digital input per.gpiod.moder.modify(|_, w| { w.moder0().input() @@ -193,7 +198,10 @@ fn main() -> ! { delay(1000); // >= 10 us // ADC CALIBRATION (15.3.8) - // 1. set ADCALDIF=0 (default) + // 1. set ADCALDIF=0 (default) for single-ended cal + per.adc1.cr.modify(|_, w| { + w.adcaldif().clear_bit() + }); // Start cal per.adc1.cr.modify(|_, w| { @@ -214,6 +222,28 @@ fn main() -> ! { // wait for ADRDY=1 while per.adc1.isr.read().adrdy().bit_is_clear() { } + // Configure sample time (15.3.12) + // 0b000 = 1.5 clocks + // 0b001 = 2.5 clocks + // 0b010 = 4.5 clocks + // 0b011 = 7.5 clocks + // 0b100 = 19.5 clocks + // 0b101 = 61.5 clocks + // 0b110 = 181.5 clocks + // 0b111 = 601.5 clocks + per.adc1.smpr1.modify(|_, w| { + unsafe { w.smp1().bits(0b101) }; + unsafe { w.smp2().bits(0b101) }; + unsafe { w.smp3().bits(0b101) }; + unsafe { w.smp4().bits(0b101) }; + unsafe { w.smp5().bits(0b101) }; + unsafe { w.smp6().bits(0b101) }; + unsafe { w.smp7().bits(0b101) }; + unsafe { w.smp8().bits(0b101) }; + unsafe { w.smp9().bits(0b101) }; + w + }); + // Configure mux'ing: SQRx (regular conversion), JSQRx (injected conversion; don't use these) // Draw from ADC1_IN2 -- PA1 per.adc1.sqr1.modify(|_, w| {