Skip to content

Commit 624ce10

Browse files
committed
[examples] Nucleo F042K6: TMP12x example
1 parent 03099b7 commit 624ce10

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2021, Christopher Durand
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#include <modm/board.hpp>
12+
#include <modm/driver/temperature/tmp12x.hpp>
13+
#include <modm/processing/timer.hpp>
14+
15+
using namespace Board;
16+
using namespace std::chrono_literals;
17+
18+
/*
19+
* Example for the TMP12x driver
20+
* It assumes a TMP121 or TM123 is connected to the following pins:
21+
* A4 CS
22+
* A5 SCK
23+
* A6 MISO
24+
*/
25+
26+
using SpiCs = GpioA4;
27+
using SpiSck = GpioA5;
28+
using SpiMiso = GpioA6;
29+
30+
int
31+
main()
32+
{
33+
Board::initialize();
34+
35+
MODM_LOG_INFO << "TMP12x test" << modm::endl;
36+
37+
SpiMaster1::connect<SpiSck::Sck, SpiMiso::Miso>();
38+
SpiMaster1::initialize<SystemClock, 1'500'000_Hz>();
39+
40+
modm::Tmp123<SpiMaster1, SpiCs> sensor;
41+
sensor.initialize();
42+
43+
modm::PeriodicTimer timer{500ms};
44+
while(true) {
45+
if (timer.execute()) {
46+
const modm::Tmp123Temperature temperature = RF_CALL_BLOCKING(sensor.read());
47+
MODM_LOG_INFO.printf("Temperature %2.2f\n", temperature.getTemperatureFloat());
48+
}
49+
}
50+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<library>
2+
<extends>modm:nucleo-f042k6</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_f042k6/tmp12x</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:driver:tmp12x</module>
9+
<module>modm:platform:spi:1</module>
10+
<module>modm:processing:timer</module>
11+
</modules>
12+
</library>

0 commit comments

Comments
 (0)