-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Nucleo F042K6: TMP12x example
- Loading branch information
1 parent
03099b7
commit 624ce10
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2021, Christopher Durand | ||
* | ||
* 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/tmp12x.hpp> | ||
#include <modm/processing/timer.hpp> | ||
|
||
using namespace Board; | ||
using namespace std::chrono_literals; | ||
|
||
/* | ||
* Example for the TMP12x driver | ||
* It assumes a TMP121 or TM123 is connected to the following pins: | ||
* A4 CS | ||
* A5 SCK | ||
* A6 MISO | ||
*/ | ||
|
||
using SpiCs = GpioA4; | ||
using SpiSck = GpioA5; | ||
using SpiMiso = GpioA6; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "TMP12x test" << modm::endl; | ||
|
||
SpiMaster1::connect<SpiSck::Sck, SpiMiso::Miso>(); | ||
SpiMaster1::initialize<SystemClock, 1'500'000_Hz>(); | ||
|
||
modm::Tmp123<SpiMaster1, SpiCs> sensor; | ||
sensor.initialize(); | ||
|
||
modm::PeriodicTimer timer{500ms}; | ||
while(true) { | ||
if (timer.execute()) { | ||
const modm::Tmp123Temperature temperature = RF_CALL_BLOCKING(sensor.read()); | ||
MODM_LOG_INFO.printf("Temperature %2.2f\n", temperature.getTemperatureFloat()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<library> | ||
<extends>modm:nucleo-f042k6</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_f042k6/tmp12x</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:driver:tmp12x</module> | ||
<module>modm:platform:spi:1</module> | ||
<module>modm:processing:timer</module> | ||
</modules> | ||
</library> |