From a2cece4d41ce8a03e32e401a18fe5cae09bfa7c0 Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sun, 6 Jul 2025 13:11:30 -0400 Subject: [PATCH 1/5] Update mcp2515.h added One Shot Mode flag and enable / disable methods --- mcp2515.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mcp2515.h b/mcp2515.h index 48e5d57..a9374c8 100644 --- a/mcp2515.h +++ b/mcp2515.h @@ -449,6 +449,7 @@ class MCP2515 uint8_t SPICS; uint32_t SPI_CLOCK; SPIClass * SPIn; + bool OSMflag; private: @@ -496,6 +497,8 @@ class MCP2515 void clearERRIF(); uint8_t errorCountRX(void); uint8_t errorCountTX(void); + void enableOSM(void); + void disableOSM(void); }; #endif From e1c517fc210cc3b8daf816e0c0ae7a1ef2c7141c Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sun, 6 Jul 2025 13:21:49 -0400 Subject: [PATCH 2/5] added One Shot Mode support --- mcp2515.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mcp2515.cpp b/mcp2515.cpp index b942b55..648b0f2 100644 --- a/mcp2515.cpp +++ b/mcp2515.cpp @@ -26,6 +26,7 @@ MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK, SPIClass * _SPI) SPI_CLOCK = _SPI_CLOCK; pinMode(SPICS, OUTPUT); digitalWrite(SPICS, HIGH); + OSMflag = false; } void MCP2515::startSPI() { @@ -179,7 +180,7 @@ MCP2515::ERROR MCP2515::setNormalMode() MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode) { - modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mode); + modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, OSMflag ? mode | CANCTRL_OSM : mode & ~(CANCTRL_OSM)); unsigned long endTime = millis() + 10; bool modeMatch = false; @@ -777,3 +778,13 @@ uint8_t MCP2515::errorCountTX(void) { return readRegister(MCP_TEC); } + +// these merely set the OSM flag +// setMode(...) or the other setXxxxMode() i.e: setNormalMode() must be called afterwards to set the correct mode with OSM +void MCP2515::enableOSM(void) { + OSMflag = true; +} + +void MCP2515::disableOSM(void) { + OSMflag = false; +} From 0f6bf0af406ac4aab7fd2b27fc346dc4f0cd9269 Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sun, 14 Sep 2025 12:38:05 -0400 Subject: [PATCH 3/5] 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 9333c76426e93bfd46e2a410ebb3286a1e3a7e17 Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sun, 14 Sep 2025 13:01:48 -0400 Subject: [PATCH 4/5] Update mcp2515.cpp refactored One Shot Mode functionality --- mcp2515.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/mcp2515.cpp b/mcp2515.cpp index 648b0f2..eda10a8 100644 --- a/mcp2515.cpp +++ b/mcp2515.cpp @@ -26,7 +26,6 @@ MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK, SPIClass * _SPI) SPI_CLOCK = _SPI_CLOCK; pinMode(SPICS, OUTPUT); digitalWrite(SPICS, HIGH); - OSMflag = false; } void MCP2515::startSPI() { @@ -178,9 +177,14 @@ MCP2515::ERROR MCP2515::setNormalMode() return setMode(CANCTRL_REQOP_NORMAL); } +MCP2515::ERROR MCP2515::setNormalOneShotMode() +{ + return setMode(CANCTRL_REQOP_NORMAL | CANCTRL_OSM); +} + MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode) { - modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, OSMflag ? mode | CANCTRL_OSM : mode & ~(CANCTRL_OSM)); + modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, mode); unsigned long endTime = millis() + 10; bool modeMatch = false; @@ -778,13 +782,3 @@ uint8_t MCP2515::errorCountTX(void) { return readRegister(MCP_TEC); } - -// these merely set the OSM flag -// setMode(...) or the other setXxxxMode() i.e: setNormalMode() must be called afterwards to set the correct mode with OSM -void MCP2515::enableOSM(void) { - OSMflag = true; -} - -void MCP2515::disableOSM(void) { - OSMflag = false; -} From ad283f71a78230d463dd37e4cf54ca98787aac43 Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sun, 14 Sep 2025 13:02:40 -0400 Subject: [PATCH 5/5] refactored One Shot Mode functionality refactored One Shot Mode functionality --- mcp2515.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mcp2515.h b/mcp2515.h index a9374c8..796507c 100644 --- a/mcp2515.h +++ b/mcp2515.h @@ -449,7 +449,6 @@ class MCP2515 uint8_t SPICS; uint32_t SPI_CLOCK; SPIClass * SPIn; - bool OSMflag; private: @@ -474,6 +473,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); @@ -497,8 +497,6 @@ class MCP2515 void clearERRIF(); uint8_t errorCountRX(void); uint8_t errorCountTX(void); - void enableOSM(void); - void disableOSM(void); }; #endif