From 9437cfe45c37cf437f357460c5f613f6f2ccf154 Mon Sep 17 00:00:00 2001 From: ptoshkov <55318963+ptoshkov@users.noreply.github.com> Date: Sun, 31 Aug 2025 18:25:11 +0300 Subject: [PATCH 1/2] Update can.h --- can.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/can.h b/can.h index 96175b1..4735f81 100644 --- a/can.h +++ b/can.h @@ -37,9 +37,9 @@ typedef __u32 canid_t; #define CAN_MAX_DLEN 8 struct can_frame { - canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ - __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ - __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); + canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ + __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ + alignas(8) __u8 data[CAN_MAX_DLEN]; }; #endif /* CAN_H_ */ From 279dcd81ace1a605aa2328c591a3f30d3b85cf5e Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sat, 20 Sep 2025 18:37:51 +0000 Subject: [PATCH 2/2] refactored One Shot Mode functionality and added CANCTRL_REQOP_OSM as a CANCTRL_REQOP_MODE --- README.md | 7 ++++--- library.properties | 2 +- mcp2515.cpp | 9 +++++++-- mcp2515.h | 4 +++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3c4a777..fa4f816 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,10 @@ To create connection with MCP2515 provide pin number where SPI CS is connected ( The available modes are listed as follows: ```C++ -mcp2515.setNormalMode(); -mcp2515.setLoopbackMode(); -mcp2515.setListenOnlyMode(); +mcp2515.setNormalMode(); // sends and receives data normally, sends acknowledgments to other nodes, when sending data, requires an acknowledgment from another node that the message was received or else, the 2515 will autonomously keep sending the same data +mcp2515.setNormalOneShotMode(); // sends and receives data normally, sends acknoledgements to other nodes that their message was received, when sending data, does not require an acknowledgement from another node that the message was received. +mcp2515.setLoopbackMode(); // data sent is immediately received and is not written to the bus, does not send acknowledgements +mcp2515.setListenOnlyMode(); // does not send data, only receives data, does not send acknowledgements ``` The available baudrates are listed as follows: ```C++ diff --git a/library.properties b/library.properties index 975adf3..3d61215 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=autowp-mcp2515 -version=1.2.1 +version=1.3.1 author=autowp maintainer=autowp sentence=Arduino MCP2515 CAN interface library diff --git a/mcp2515.cpp b/mcp2515.cpp index b942b55..1302bfe 100644 --- a/mcp2515.cpp +++ b/mcp2515.cpp @@ -177,9 +177,14 @@ MCP2515::ERROR MCP2515::setNormalMode() return setMode(CANCTRL_REQOP_NORMAL); } +MCP2515::ERROR MCP2515::setNormalOneShotMode() +{ + return setMode(CANCTRL_REQOP_OSM); +} + MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode) { - modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mode); + modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, mode); unsigned long endTime = millis() + 10; bool modeMatch = false; @@ -776,4 +781,4 @@ uint8_t MCP2515::errorCountRX(void) uint8_t MCP2515::errorCountTX(void) { return readRegister(MCP_TEC); -} +} \ No newline at end of file diff --git a/mcp2515.h b/mcp2515.h index 48e5d57..ede5e95 100644 --- a/mcp2515.h +++ b/mcp2515.h @@ -274,6 +274,7 @@ class MCP2515 enum /*class*/ CANCTRL_REQOP_MODE : uint8_t { CANCTRL_REQOP_NORMAL = 0x00, + CANCTRL_REQOP_OSM = 0x08, CANCTRL_REQOP_SLEEP = 0x20, CANCTRL_REQOP_LOOPBACK = 0x40, CANCTRL_REQOP_LISTENONLY = 0x60, @@ -473,6 +474,7 @@ class MCP2515 ERROR setSleepMode(); ERROR setLoopbackMode(); ERROR setNormalMode(); + ERROR setNormalOneShotMode(); ERROR setClkOut(const CAN_CLKOUT divisor); ERROR setBitrate(const CAN_SPEED canSpeed); ERROR setBitrate(const CAN_SPEED canSpeed, const CAN_CLOCK canClock); @@ -498,4 +500,4 @@ class MCP2515 uint8_t errorCountTX(void); }; -#endif +#endif \ No newline at end of file