Skip to content

Commit 7b8f2cc

Browse files
committed
[examples] Add ADS868x example
1 parent 829762b commit 7b8f2cc

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2021, Raphael Lehmann
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+
12+
#include <modm/board.hpp>
13+
#include <modm/driver/adc/ads868x.hpp>
14+
15+
using namespace Board;
16+
17+
using SpiMaster = SpiMaster1;
18+
using Mosi = GpioB5;
19+
using Miso = GpioB4;
20+
using Sck = GpioB3;
21+
using Cs = GpioA4;
22+
using Rst = GpioF12;
23+
24+
using Ads868x = modm::Ads868x<SpiMaster, Cs, Rst>;
25+
26+
Ads868x adc{};
27+
28+
int
29+
main()
30+
{
31+
Board::initialize();
32+
Leds::setOutput();
33+
34+
MODM_LOG_INFO << "ADS868X Demo on Nucleo-F429ZI\n" << modm::endl;
35+
36+
SpiMaster::initialize<Board::SystemClock, 10_MHz>();
37+
SpiMaster::connect<Sck::Sck, Mosi::Mosi, Miso::Miso>();
38+
39+
Rst::setOutput();
40+
Cs::setOutput(true);
41+
42+
MODM_LOG_INFO << "Initializing ADC..." << modm::endl;
43+
adc.initialize();
44+
45+
uint32_t counter(0);
46+
47+
while (true)
48+
{
49+
Leds::write(counter % ((1 << (Leds::width+1)) - 1));
50+
51+
uint16_t result = adc.singleConversion();
52+
MODM_LOG_INFO.printf("ADC Manual: %05u\n", result);
53+
54+
modm::delay(Button::read() ? 1ms : 500ms);
55+
}
56+
57+
return 0;
58+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<library>
2+
<extends>modm:nucleo-f429zi</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/nucleo_f429zi/adc_ads868x</option>
5+
</options>
6+
<modules>
7+
<module>modm:build:scons</module>
8+
<module>modm:platform:spi:1</module>
9+
<module>modm:driver:ads868x</module>
10+
</modules>
11+
</library>

0 commit comments

Comments
 (0)