diff --git a/mcp2515.cpp b/mcp2515.cpp index 6b86fb9..90ef421 100644 --- a/mcp2515.cpp +++ b/mcp2515.cpp @@ -172,8 +172,14 @@ MCP2515::ERROR MCP2515::setNormalMode() MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode) { - modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mode); + // Check for oneshot mode. + uint8_t mcpMode = osmFlag ? mode | CANCTRL_OSM : mode & ~(CANCTRL_OSM); + // Writing CANCTRL register. + modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mcpMode); + + // Checking from CANSTAT register only confirms the main working modes, + // and interrupts. Bit 4 is unimplemented. unsigned long endTime = millis() + 10; bool modeMatch = false; while (millis() < endTime) { @@ -764,3 +770,11 @@ uint8_t MCP2515::errorCountTX(void) { return readRegister(MCP_TEC); } + +void MCP2515::enableOSM(void) { + osmFlag = true; +} + +void MCP2515::disableOSM(void) { + osmFlag = false; +} diff --git a/mcp2515.h b/mcp2515.h index 5d9bef7..83bc87f 100644 --- a/mcp2515.h +++ b/mcp2515.h @@ -443,6 +443,7 @@ class MCP2515 } RXB[N_RXBUFFERS]; uint8_t SPICS; + bool osmFlag = false; private: @@ -490,6 +491,10 @@ class MCP2515 void clearERRIF(); uint8_t errorCountRX(void); uint8_t errorCountTX(void); + + // ONE SHOT MODE + void enableOSM(void); + void disableOSM(void); }; #endif