-
Notifications
You must be signed in to change notification settings - Fork 153
changed mcp2515 driver to use nonblocking spi #817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 15 commits
148e788
10b0e46
33db784
21e4036
03639b4
bf7b0fa
9584f22
8e6a52f
bda5887
7c9065d
5357bc2
c177db3
d737638
f94d31a
6f773fc
33a621f
ed406ca
ec7cf30
a34f35d
6c79bc2
6e6e359
49091cf
dadd55f
5ac11f4
2b5b355
5aa143e
4d7df65
2e4ad3b
5906e17
0ff3eef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (c) 2013, Kevin Läufer | ||
* Copyright (c) 2013-2017, Niklas Hauser | ||
* Copyright (c) 2016, 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/platform/spi/spi_master_1.hpp> | ||
#include <modm/platform/spi/spi_master_2.hpp> | ||
#include <modm/processing/protothread.hpp> | ||
#include <modm/driver/can/mcp2515.hpp> | ||
|
||
|
||
#define SENDER 0 | ||
|
||
// Set the log level | ||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::DEBUG | ||
|
||
// If you use a different SPI instance, you may have to also choose different | ||
// GPIOs to connect to. | ||
using Cs = GpioOutputA4; | ||
using Mosi = GpioOutputB5; | ||
using Miso = GpioInputB4; | ||
using Sck = GpioOutputB3; | ||
using Int = GpioInputC7; | ||
using SpiMaster = SpiMaster1; | ||
// Note that you can also use a bit-banged SPI driver as a drop-in replacement | ||
// using SpiMaster = BitBangSpiMaster<Sck, Mosi, Miso>; | ||
|
||
// Default filters to receive any extended CAN frame | ||
FLASH_STORAGE(uint8_t canFilter[]) = { | ||
MCP2515_FILTER_EXTENDED(0), // Filter 0 | ||
MCP2515_FILTER_EXTENDED(0), // Filter 1 | ||
|
||
MCP2515_FILTER_EXTENDED(0), // Filter 2 | ||
MCP2515_FILTER_EXTENDED(0), // Filter 3 | ||
MCP2515_FILTER_EXTENDED(0), // Filter 4 | ||
MCP2515_FILTER_EXTENDED(0), // Filter 5 | ||
|
||
MCP2515_FILTER_EXTENDED(0), // Mask 0 | ||
MCP2515_FILTER_EXTENDED(0), // Mask 1 | ||
}; | ||
|
||
modm::Mcp2515<SpiMaster, Cs, Int> mcp2515; | ||
|
||
class MyTask : modm::pt::Protothread | ||
{ | ||
public: | ||
MyTask() : message_{0x1337}{} | ||
|
||
bool | ||
run() | ||
{ | ||
PT_BEGIN(); | ||
|
||
MODM_LOG_INFO << "Initializing mcp2515 ..." << modm::endl; | ||
// Configure MCP2515 and set the filters | ||
initialized_ = mcp2515.initialize<8_MHz, 500_kbps>(); | ||
MODM_LOG_INFO << "Success: " << initialized_ << modm::endl; | ||
mcp2515.setFilter(modm::accessor::asFlash(canFilter)); | ||
MODM_LOG_INFO << "Running ... " << modm::endl; | ||
#if SENDER == 0 | ||
while (initialized_) | ||
kikass13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// receive messages | ||
if (mcp2515.isMessageAvailable()) | ||
{ | ||
MODM_LOG_INFO << "Message Available ... " << modm::endl; | ||
mcp2515.getMessage(message_); | ||
MODM_LOG_INFO << "Received message: " << modm::hex << message_.identifier << modm::endl; | ||
} | ||
PT_CALL(mcp2515.update()); | ||
} | ||
#else | ||
while (initialized_) | ||
{ | ||
wait_.restart(500ms); | ||
PT_WAIT_UNTIL(wait_.isExpired()); | ||
message_.length = 2; | ||
message_.data[0] = 0xab; | ||
message_.data[1] = 0xcd; | ||
MODM_LOG_INFO << "Sending Message ... "<< modm::endl; | ||
mcp2515.sendMessage(message_); | ||
PT_CALL(mcp2515.update()); | ||
} | ||
#endif | ||
|
||
PT_END(); | ||
} | ||
|
||
private: | ||
modm::can::Message message_; | ||
bool initialized_; | ||
modm::ShortTimeout wait_; | ||
}; | ||
|
||
MyTask task; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
MODM_LOG_INFO << "Hello" << modm::endl; | ||
kikass13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Initialize SPI interface and the other pins | ||
// needed by the MCP2515 | ||
SpiMaster::connect<Miso::Miso, Mosi::Mosi, Sck::Sck>(); | ||
/// we initialize a higher baud rate then n the avr example, dunnow hats the mcp2515 is capable | ||
/// of | ||
SpiMaster::initialize<Board::SystemClock, 20_MHz>(); | ||
kikass13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Cs::setOutput(); | ||
Int::setInput(Gpio::InputType::PullUp); | ||
|
||
while (true) { | ||
task.run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<library> | ||
<extends>modm:nucleo-f439zi</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/stm32f4_discovery/mcp2515</option> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
</options> | ||
<modules> | ||
<module>modm:platform:gpio</module> | ||
<module>modm:platform:spi.bitbang</module> | ||
<module>modm:platform:spi:1</module> | ||
<module>modm:platform:spi:2</module> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not used in the example. Remove. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<module>modm:build:scons</module> | ||
|
||
<module>modm:processing:protothread</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:driver:mcp2515</module> | ||
|
||
</modules> | ||
</library> |
+0 −13 | .github/workflows/update.yml | |
+ − | CrashDebug/bins/lin64/CrashDebug | |
+ − | CrashDebug/bins/osx64/CrashDebug | |
+ − | CrashDebug/bins/win32/CrashDebug.exe | |
+5 −12 | update.py |
Uh oh!
There was an error while loading. Please reload this page.