Skip to content

Commit

Permalink
[examples] Nucleo F042K6: TMP12x example
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Oct 21, 2021
1 parent 03099b7 commit 624ce10
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
50 changes: 50 additions & 0 deletions examples/nucleo_f042k6/tmp12x/main.cpp
@@ -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());
}
}
}
12 changes: 12 additions & 0 deletions examples/nucleo_f042k6/tmp12x/project.xml
@@ -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>

0 comments on commit 624ce10

Please sign in to comment.