From 65bbccf2c971527562c36f6c14546ffe29a2feec Mon Sep 17 00:00:00 2001 From: Henrik Hose Date: Tue, 2 May 2023 23:22:00 +0200 Subject: [PATCH] [driver] add stm32f469_disco example for max31865 --- .../stm32f469_discovery/max31865/main.cpp | 88 +++++++++++++++++++ .../stm32f469_discovery/max31865/project.xml | 14 +++ 2 files changed, 102 insertions(+) create mode 100644 examples/stm32f469_discovery/max31865/main.cpp create mode 100644 examples/stm32f469_discovery/max31865/project.xml diff --git a/examples/stm32f469_discovery/max31865/main.cpp b/examples/stm32f469_discovery/max31865/main.cpp new file mode 100644 index 0000000000..af655aeeea --- /dev/null +++ b/examples/stm32f469_discovery/max31865/main.cpp @@ -0,0 +1,88 @@ +// coding: utf-8 +/* + * Copyright (c) 2023, Henrik Hose + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +using namespace Board; + +using SpiMaster = modm::platform::SpiMaster2; + +using Cs = D9; +using Mosi = D11; +using Miso = D12; +using Sck = D13; + +class ThermocoupleThread : public modm::pt::Protothread +{ +public: + ThermocoupleThread() : data{}, pt100(data) {} + + bool + run() + { + PT_BEGIN(); + PT_CALL(pt100.initialize()); + + while (true) + { + MODM_LOG_INFO << "\nNew readout:" << modm::endl; + PT_CALL(pt100.readout()); + + MODM_LOG_INFO << " resistance : " << data.getResistance() << " Ohm" + << modm::endl; + MODM_LOG_INFO << " temperature fast: " << data.getTemperatureFast() << " degrees" + << modm::endl; + MODM_LOG_INFO << " temperature precise: " << data.getTemperaturePrecise() << " degrees" + << modm::endl; + + timeout.restart(std::chrono::milliseconds(1000)); + PT_WAIT_UNTIL(timeout.isExpired()); + } + + PT_END(); + } + +private: + using Max31865 = modm::Max31865; + Max31865::Data data; + Max31865 pt100; + + modm::ShortTimeout timeout; +}; + +ThermocoupleThread pt100Thread{}; + +int +main() +{ + Board::initialize(); + Cs::setOutput(modm::Gpio::High); + + SpiMaster::connect(); + SpiMaster::initialize(); + + MODM_LOG_INFO << "==========MAX 31865 Test==========" << modm::endl; + MODM_LOG_DEBUG << "Debug logging here" << modm::endl; + MODM_LOG_INFO << "Info logging here" << modm::endl; + MODM_LOG_WARNING << "Warning logging here" << modm::endl; + MODM_LOG_ERROR << "Error logging here" << modm::endl; + MODM_LOG_INFO << "===============================" << modm::endl; + + while (true) + { + pt100Thread.run(); + Board::LedOrange::toggle(); + } + + return 0; +} \ No newline at end of file diff --git a/examples/stm32f469_discovery/max31865/project.xml b/examples/stm32f469_discovery/max31865/project.xml new file mode 100644 index 0000000000..8c5e189536 --- /dev/null +++ b/examples/stm32f469_discovery/max31865/project.xml @@ -0,0 +1,14 @@ + + modm:disco-f469ni + + + + + modm:driver:max31865 + modm:platform:gpio + modm:platform:spi:2 + modm:processing:protothread + modm:processing:timer + modm:build:scons + + \ No newline at end of file