From 69ed2fc701e96e382163b56cc5e166cd65738d6b Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Wed, 29 Aug 2018 00:43:29 +0200 Subject: [PATCH] max6675 library works --- src/main.rs | 31 +++++++++++++++++-------------- src/max6675.rs | 16 +++++++++------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 453d601..aeb7c3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,9 +32,9 @@ fn configure_clocks(rcc: &mut rcc::RCC) { rcc.clock_config .configure(|c| { - c.set_pll_multiplier(10) - .set_pll_source(rcc::PllSource::HsiDiv2) - }); + c.set_pll_multiplier(10) + .set_pll_source(rcc::PllSource::HsiDiv2) + }); rcc.clock_control.set_pll_on(true); while !rcc.clock_control.pll_ready() {} @@ -64,16 +64,17 @@ fn configure_peripherals(rcc: &mut hcl::platform::rcc::RCC, .set_output_config(7, gpio::OutputConfig::AfPushPull) // MISO1 .set_mode(6, gpio::PinMode::Input) + .set_input_config(6, gpio::InputConfig::PullUpDown) // NSS1 .set_mode(4, gpio::PinMode::Output50MHz) .set_output_config(4, gpio::OutputConfig::PushPull) }); usart.configure(|u| { - u.set_enabled(true) - .set_tx_enabled(true) - .set_baudgen((21, 11)) - }); // 115.2 kbaud + u.set_enabled(true) + .set_tx_enabled(true) + .set_baudgen((21, 11)) + }); // 115.2 kbaud } @@ -92,16 +93,18 @@ fn run(mut scs: scs::Instance, mut p: hcl::platform::Instance) { loop { - for i in 0u16..0xffff { - let res = max6675::read(spi, gpio, 4); + let res = max6675::read(spi, gpio, 4); - let msg = match res { - Ok(temp) => format!("> {}\r\n", temp).into_bytes(), - Err(err) => format!("Error > {}\r\n", err).into_bytes(), - }; + let msg = match res { + Ok(temp) => format!("> {}\r\n", temp).into_bytes(), + Err(err) => format!("Error > {}\r\n", err).into_bytes(), + }; - printer.print(msg); + printer.print(msg); + + for y in 0u32..0xFFFFFF { + unsafe { asm!("nop" :::: "volatile") }; } } } diff --git a/src/max6675.rs b/src/max6675.rs index 413d16a..2b64b46 100644 --- a/src/max6675.rs +++ b/src/max6675.rs @@ -11,13 +11,15 @@ pub fn read(spi: &mut PeripheralRef, GPIOAddr: Location { spi.configure(|s| { - s.set_enabled(true) - .set_master_mode(true) - .set_software_slave_select(true) - .set_clock_divider(128) - .set_data_16bit(true) - .set_clock_skip_first(true) - }); + s.set_enabled(true) + .set_master_mode(true) + .set_software_slave_select(true) + .set_clock_divider(128) + .set_data_16bit(true) + .set_clock_skip_first(true) + // required for master mode, even if ss is done manually + .set_slave_select_output_enabled(true) + }); nss_gpio.reset_bit(nss_idx);