Skip to content

Commit 65bbccf

Browse files
committed
[driver] add stm32f469_disco example for max31865
1 parent 8bd9829 commit 65bbccf

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// coding: utf-8
2+
/*
3+
* Copyright (c) 2023, Henrik Hose
4+
*
5+
* This file is part of the modm project.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
10+
*/
11+
12+
#include <modm/board.hpp>
13+
#include <modm/driver/temperature/max31865.hpp>
14+
#include <modm/processing.hpp>
15+
16+
using namespace Board;
17+
18+
using SpiMaster = modm::platform::SpiMaster2;
19+
20+
using Cs = D9;
21+
using Mosi = D11;
22+
using Miso = D12;
23+
using Sck = D13;
24+
25+
class ThermocoupleThread : public modm::pt::Protothread
26+
{
27+
public:
28+
ThermocoupleThread() : data{}, pt100(data) {}
29+
30+
bool
31+
run()
32+
{
33+
PT_BEGIN();
34+
PT_CALL(pt100.initialize());
35+
36+
while (true)
37+
{
38+
MODM_LOG_INFO << "\nNew readout:" << modm::endl;
39+
PT_CALL(pt100.readout());
40+
41+
MODM_LOG_INFO << " resistance : " << data.getResistance() << " Ohm"
42+
<< modm::endl;
43+
MODM_LOG_INFO << " temperature fast: " << data.getTemperatureFast() << " degrees"
44+
<< modm::endl;
45+
MODM_LOG_INFO << " temperature precise: " << data.getTemperaturePrecise() << " degrees"
46+
<< modm::endl;
47+
48+
timeout.restart(std::chrono::milliseconds(1000));
49+
PT_WAIT_UNTIL(timeout.isExpired());
50+
}
51+
52+
PT_END();
53+
}
54+
55+
private:
56+
using Max31865 = modm::Max31865<SpiMaster, Cs, modm::max31865::pt100>;
57+
Max31865::Data data;
58+
Max31865 pt100;
59+
60+
modm::ShortTimeout timeout;
61+
};
62+
63+
ThermocoupleThread pt100Thread{};
64+
65+
int
66+
main()
67+
{
68+
Board::initialize();
69+
Cs::setOutput(modm::Gpio::High);
70+
71+
SpiMaster::connect<Miso::Miso, Mosi::Mosi, Sck::Sck>();
72+
SpiMaster::initialize<Board::SystemClock, 351_kHz>();
73+
74+
MODM_LOG_INFO << "==========MAX 31865 Test==========" << modm::endl;
75+
MODM_LOG_DEBUG << "Debug logging here" << modm::endl;
76+
MODM_LOG_INFO << "Info logging here" << modm::endl;
77+
MODM_LOG_WARNING << "Warning logging here" << modm::endl;
78+
MODM_LOG_ERROR << "Error logging here" << modm::endl;
79+
MODM_LOG_INFO << "===============================" << modm::endl;
80+
81+
while (true)
82+
{
83+
pt100Thread.run();
84+
Board::LedOrange::toggle();
85+
}
86+
87+
return 0;
88+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<library>
2+
<extends>modm:disco-f469ni</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/stm32f469_discovery/max31865</option>
5+
</options>
6+
<modules>
7+
<module>modm:driver:max31865</module>
8+
<module>modm:platform:gpio</module>
9+
<module>modm:platform:spi:2</module>
10+
<module>modm:processing:protothread</module>
11+
<module>modm:processing:timer</module>
12+
<module>modm:build:scons</module>
13+
</modules>
14+
</library>

0 commit comments

Comments
 (0)