-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (59 loc) · 1.91 KB
/
main.cpp
File metadata and controls
74 lines (59 loc) · 1.91 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) 2023, Raphael Lehmann
*
* 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/debug/logger.hpp>
using namespace modm::literals;
using namespace modm::platform;
using namespace Board;
int
main()
{
Board::initialize();
MODM_LOG_INFO << "CAN Test Program" << modm::endl;
MODM_LOG_INFO << "Mcan1: Initializing with 125kbps / 1Mbps (FDCAN) for boards CAN transceiver (PC12/PC14)." << modm::endl;
// Mcan1 is connted in Board::initialize(); CAN transceiver on the dev board
Mcan1::initialize<Board::SystemClock, 125_kbps, 1_pct, 1_Mbps>(12);
MODM_LOG_INFO << "Mcan1: Setting up Filter to receive every message." << modm::endl;
Mcan1::setExtendedFilter(0, Mcan1::FilterConfig::Fifo0,
modm::can::ExtendedIdentifier(0),
modm::can::ExtendedMask(0));
Mcan1::setStandardFilter(0, Mcan1::FilterConfig::Fifo0,
modm::can::StandardIdentifier(0),
modm::can::StandardMask(0));
Mcan1::setMode(Mcan1::Mode::TestExternalLoopback);
Mcan1::setErrorInterruptCallback([]{
Board::Led1::set();
});
uint32_t counter{0};
while (true)
{
counter++;
MODM_LOG_INFO << "loop: " << counter << modm::endl;
modm::can::Message txMsg{counter, 64};
txMsg.setExtended(true);
for (size_t i = 0; i < txMsg.capacity; ++i) {
txMsg.data[i] = counter;
}
MODM_LOG_INFO << "Mcan1: Sending message... " << txMsg << modm::endl;
Mcan1::sendMessage(txMsg);
if (Mcan1::isMessageAvailable())
{
MODM_LOG_INFO << "Mcan1: Message is available... ";
modm::can::Message rxMsg;
if (Mcan1::getMessage(rxMsg))
MODM_LOG_INFO << rxMsg << modm::endl;
else
MODM_LOG_INFO << " but getting message FAILED" << modm::endl;
}
Led0::toggle();
modm::delay(500ms);
}
return 0;
}