Skip to content

Commit c2da2cf

Browse files
committed
[example] Long-frame CAN example for samv71_xplained_ultra
1 parent f042a31 commit c2da2cf

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2023, 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+
#include <modm/board.hpp>
12+
#include <modm/debug/logger.hpp>
13+
14+
using namespace modm::literals;
15+
using namespace modm::platform;
16+
using namespace Board;
17+
18+
// Set the log level
19+
#undef MODM_LOG_LEVEL
20+
#define MODM_LOG_LEVEL modm::log::INFO
21+
22+
int
23+
main()
24+
{
25+
Board::initialize();
26+
27+
MODM_LOG_INFO << "CAN Test Program" << modm::endl;
28+
29+
MODM_LOG_INFO << "Mcan1: Initializing with 125kbps / 1Mbps (FDCAN) for boards CAN transceiver (PC12/PC14)." << modm::endl;
30+
// Mcan1 is connted in Board::initialize(); CAN transceiver on the dev board
31+
Mcan1::initialize<Board::SystemClock, 125_kbps, 1_pct, 1_Mbps>(12);
32+
33+
MODM_LOG_INFO << "Mcan1: Setting up Filter to receive every message." << modm::endl;
34+
Mcan1::setExtendedFilter(0, Mcan1::FilterConfig::Fifo0,
35+
modm::can::ExtendedIdentifier(0),
36+
modm::can::ExtendedMask(0));
37+
Mcan1::setStandardFilter(0, Mcan1::FilterConfig::Fifo0,
38+
modm::can::StandardIdentifier(0),
39+
modm::can::StandardMask(0));
40+
41+
Mcan1::setMode(Mcan1::Mode::TestExternalLoopback);
42+
43+
Mcan1::setErrorInterruptCallback([](){
44+
Board::Led1::set();
45+
});
46+
47+
uint32_t counter{0};
48+
49+
while (true)
50+
{
51+
counter++;
52+
MODM_LOG_INFO << "loop: " << counter << modm::endl;
53+
54+
modm::can::Message txMsg{counter, 64};
55+
txMsg.setExtended(true);
56+
for (size_t i = 0; i < txMsg.capacity; ++i) {
57+
txMsg.data[i] = counter;
58+
}
59+
MODM_LOG_INFO << "Mcan1: Sending message... " << txMsg << modm::endl;
60+
Mcan1::sendMessage(txMsg);
61+
62+
if (Mcan1::isMessageAvailable())
63+
{
64+
MODM_LOG_INFO << "Mcan1: Message is available... ";
65+
modm::can::Message rxMsg;
66+
if (Mcan1::getMessage(rxMsg))
67+
MODM_LOG_INFO << rxMsg << modm::endl;
68+
else
69+
MODM_LOG_INFO << " but getting message FAILED" << modm::endl;
70+
}
71+
72+
Led0::toggle();
73+
modm::delay(500ms);
74+
}
75+
76+
return 0;
77+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<library>
2+
<extends>modm:samv71-xplained-ultra</extends>
3+
<options>
4+
<option name="modm:build:build.path">../../../build/samv71_xplained_ultra/fdcan</option>
5+
<option name="modm:architecture:can:message.buffer">64</option>
6+
</options>
7+
<modules>
8+
<module>modm:build:scons</module>
9+
</modules>
10+
</library>

0 commit comments

Comments
 (0)