Skip to content

Commit

Permalink
[driver] add stm32f469_disco example for max31865
Browse files Browse the repository at this point in the history
  • Loading branch information
hshose committed May 2, 2023
1 parent 8bd9829 commit 65bbccf
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
88 changes: 88 additions & 0 deletions examples/stm32f469_discovery/max31865/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <modm/board.hpp>
#include <modm/driver/temperature/max31865.hpp>
#include <modm/processing.hpp>

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<SpiMaster, Cs, modm::max31865::pt100>;
Max31865::Data data;
Max31865 pt100;

modm::ShortTimeout timeout;
};

ThermocoupleThread pt100Thread{};

int
main()
{
Board::initialize();
Cs::setOutput(modm::Gpio::High);

SpiMaster::connect<Miso::Miso, Mosi::Mosi, Sck::Sck>();
SpiMaster::initialize<Board::SystemClock, 351_kHz>();

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;
}
14 changes: 14 additions & 0 deletions examples/stm32f469_discovery/max31865/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<library>
<extends>modm:disco-f469ni</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f469_discovery/max31865</option>
</options>
<modules>
<module>modm:driver:max31865</module>
<module>modm:platform:gpio</module>
<module>modm:platform:spi:2</module>
<module>modm:processing:protothread</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
</modules>
</library>

0 comments on commit 65bbccf

Please sign in to comment.