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; +} 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