Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion mcp2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions mcp2515.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ class MCP2515
} RXB[N_RXBUFFERS];

uint8_t SPICS;
bool osmFlag = false;

private:

Expand Down Expand Up @@ -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