Skip to content

Commit 9333c76

Browse files
Update mcp2515.cpp
refactored One Shot Mode functionality
1 parent 0f6bf0a commit 9333c76

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

mcp2515.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK, SPIClass * _SPI)
2626
SPI_CLOCK = _SPI_CLOCK;
2727
pinMode(SPICS, OUTPUT);
2828
digitalWrite(SPICS, HIGH);
29-
OSMflag = false;
3029
}
3130

3231
void MCP2515::startSPI() {
@@ -178,9 +177,14 @@ MCP2515::ERROR MCP2515::setNormalMode()
178177
return setMode(CANCTRL_REQOP_NORMAL);
179178
}
180179

180+
MCP2515::ERROR MCP2515::setNormalOneShotMode()
181+
{
182+
return setMode(CANCTRL_REQOP_NORMAL | CANCTRL_OSM);
183+
}
184+
181185
MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode)
182186
{
183-
modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, OSMflag ? mode | CANCTRL_OSM : mode & ~(CANCTRL_OSM));
187+
modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, mode);
184188

185189
unsigned long endTime = millis() + 10;
186190
bool modeMatch = false;
@@ -778,13 +782,3 @@ uint8_t MCP2515::errorCountTX(void)
778782
{
779783
return readRegister(MCP_TEC);
780784
}
781-
782-
// these merely set the OSM flag
783-
// setMode(...) or the other setXxxxMode() i.e: setNormalMode() must be called afterwards to set the correct mode with OSM
784-
void MCP2515::enableOSM(void) {
785-
OSMflag = true;
786-
}
787-
788-
void MCP2515::disableOSM(void) {
789-
OSMflag = false;
790-
}

0 commit comments

Comments
 (0)