Skip to content
Closed
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
13 changes: 12 additions & 1 deletion mcp2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions mcp2515.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ class MCP2515
uint8_t SPICS;
uint32_t SPI_CLOCK;
SPIClass * SPIn;
bool OSMflag;

private:

Expand Down Expand Up @@ -496,6 +497,8 @@ class MCP2515
void clearERRIF();
uint8_t errorCountRX(void);
uint8_t errorCountTX(void);
void enableOSM(void);
void disableOSM(void);
};

#endif