Skip to content

Commit

Permalink
WIP [example] Add CAN example for SAMV71-XPLAINED board
Browse files Browse the repository at this point in the history
  • Loading branch information
rleh committed Feb 5, 2023
1 parent b39ef41 commit bcd8ee2
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
84 changes: 84 additions & 0 deletions examples/samv71_xplained_ultra/can/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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>
#include <modm/board.hpp>
#include <modm/platform/can/can_0.hpp>

using namespace modm::literals;
using namespace modm::platform;

// Set the log level
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::INFO

int
main()
{
Board::initialize();

MODM_LOG_INFO << "CAN Test Program" << modm::endl;

MODM_LOG_INFO << "Initializing Mcan0..." << modm::endl;
// Initialize Mcan0
//Mcan0::connect<GpioB2::Tx, GpioB3::Rx>(InputType::PullUp); // TODO
Mcan0::initialize<Board::SystemClock, 125_kbps, 1_pct, 500_kbps>(9);

MODM_LOG_INFO << "Setting up Filter for Mcan0..." << modm::endl;
// Receive every extended id message
Mcan0::setExtendedFilter(0, Mcan0::FilterConfig::Fifo0,
modm::can::ExtendedIdentifier(0),
modm::can::ExtendedMask(0));

MODM_LOG_INFO << "Initializing Mcan1..." << modm::endl;
// Initialize Mcan1
//Mcan1::connect<GpioC12::Tx, GpioC14::Rx>(InputType::PullUp); // TODO
Mcan1::initialize<Board::SystemClock, 125_kbps, 1_pct, 500_kbps>(12);

MODM_LOG_INFO << "Setting up Filter for Mcan1..." << modm::endl;
// Receive every message
Mcan1::setExtendedFilter(0, Mcan1::FilterConfig::Fifo0,
modm::can::ExtendedIdentifier(0),
modm::can::ExtendedMask(0));

// Send a message
MODM_LOG_INFO << "Sending message on Mcan0..." << modm::endl;
modm::can::Message msg1(1, 1);
msg1.setExtended(true);
msg1.data[0] = 0x11;
Mcan0::sendMessage(msg1);

// Send a message
MODM_LOG_INFO << "Sending message on Mcan1..." << modm::endl;
msg1.data[0] = 0x22;
Mcan1::sendMessage(msg1);


while (true)
{
if (Mcan0::isMessageAvailable())
{
MODM_LOG_INFO << "Mcan0: Message is available..." << modm::endl;
modm::can::Message message;
Mcan0::getMessage(message);
MODM_LOG_INFO << message << modm::endl;
}
if (Mcan1::isMessageAvailable())
{
MODM_LOG_INFO << "Mcan1: Message is available..." << modm::endl;
modm::can::Message message;
Mcan1::getMessage(message);
MODM_LOG_INFO << message << modm::endl;
}
}

return 0;
}
10 changes: 10 additions & 0 deletions examples/samv71_xplained_ultra/can/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<library>
<extends>modm:samv71-xplained-ultra</extends>
<options>
<option name="modm:build:build.path">../../../build/samv71_xplained_ultra/blink</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:platform:can:*</module>
</modules>
</library>

0 comments on commit bcd8ee2

Please sign in to comment.