-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (62 loc) · 1.92 KB
/
main.cpp
File metadata and controls
74 lines (62 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2017, Sascha Schade
* Copyright (c) 2018, Niklas Hauser
*
* 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>
static void
displayMessage(const modm::can::Message& message, const uint8_t& filter_id)
{
static uint32_t receiveCounter = 0;
receiveCounter++;
MODM_LOG_INFO << "filter_id = " << filter_id << ", ";
MODM_LOG_INFO << message << modm::endl;
MODM_LOG_INFO << "# received=" << receiveCounter << modm::endl;
}
// ----------------------------------------------------------------------------
int
main()
{
Board::initialize();
MODM_LOG_INFO << "CAN Test Program" << modm::endl;
MODM_LOG_INFO << "Initializing Can..." << modm::endl;
// Initialize Can
if (false) {
Can::connect<GpioInputA11::Rx, GpioOutputA12::Tx>(Gpio::InputType::PullUp);
} else {
Can::connect<GpioInputB8::Rx, GpioOutputB9::Tx>(Gpio::InputType::PullUp);
}
Can::initialize<Board::SystemClock, 125_kbps>(9);
MODM_LOG_INFO << "Setting up Filter for Can..." << modm::endl;
// Receive every message
CanFilter::setFilter(0, CanFilter::FIFO0,
CanFilter::ExtendedIdentifier(0),
CanFilter::ExtendedFilterMask(0));
CanFilter::setFilter(1, CanFilter::FIFO0,
CanFilter::StandardIdentifier(0),
CanFilter::StandardFilterMask(0));
// Send a message
MODM_LOG_INFO << "Sending message on Can... nn" << modm::endl;
modm::can::Message msg1(1, 1);
msg1.setExtended(true);
msg1.data[0] = 0x11;
Can::sendMessage(msg1);
while (true)
{
if (Can::isMessageAvailable())
{
MODM_LOG_INFO << "Can: Message is available..." << modm::endl;
modm::can::Message message;
uint8_t filter_id;
Can::getMessage(message, &filter_id);
displayMessage(message, filter_id);
Board::LedGreen::toggle();
}
}
return 0;
}