arduino-mcp2515
arduino-mcp2515 copied to clipboard
Added support for One-Shot Mode (OSM)
Just added the support for One-Shot Mode.
Simple usage is to call the "enableOSM"
or "disableOSM"
member function before configuring the mode of operation.
Let me know if any optimization is needed or could be done in a better way.
line 176 needs to be ==
I guess not. No change is necessary.
That line is simply storing the new value into the mode variable by the decision of osmFlag
. osmFlag
itself is conditional logic.
I get compiler errors the way it is:
C:\Users\andre\Documents\Arduino\libraries\arduino-mcp2515\mcp2515.cpp: In member function 'MCP2515::ERROR MCP2515::setMode(MCP2515::CANCTRL_REQOP_MODE)': C:\Users\andre\Documents\Arduino\libraries\arduino-mcp2515\mcp2515.cpp:176:63: error: assignment of read-only parameter 'mode' mode = osmFlag ? mode | CANCTRL_OSM : mode & ~(CANCTRL_OSM); ^ C:\Users\andre\Documents\Arduino\libraries\arduino-mcp2515\mcp2515.cpp:176:20: error: invalid conversion from 'int' to 'MCP2515::CANCTRL_REQOP_MODE' [-fpermissive] mode = osmFlag ? mode | CANCTRL_OSM : mode & ~(CANCTRL_OSM); ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and since its basically the same as if( mode = osmFlag) {mode | CANCTRL_OSM} else {mode & ~(CANCTRL_OSM)}
I´d say it needs to be a comparison, not an assignment.
It still send 2 messages as a burst tho, not 1...
Haha thanks for showing me indirectly a mistake here.
The solution is to remove const keyword. SIMPLE. Or use a entirely new variable. I,ll make the changes tom its late here.
Plz consult how shorthand if are used. https://www.w3schools.com/cpp/cpp_conditions_shorthand.asp
Here is the doc of MCP2515: http://ww1.microchip.com/downloads/en/DeviceDoc/80179g.pdf It is a bug of this chip (see the page 2). If the SPI is not set to disabled (or using other solutions), the chip will keep pending. That is why the chip keep send can frames to the bus.
I think #30 solved the problem temporarily, we can direct operate SPI. But "Use hardware pins (TXnRTS) to request transmission" may be the best solution.
@DeltaC6
This don't work: 179: modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mcpMode);
CANCTRL_REQOP
mask exclude CANCTRL_OSM
bit.
This work: modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, mcpMode);
This don't work:
179: modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mcpMode);
CANCTRL_REQOP
mask excludeCANCTRL_OSM
bit.This work:
modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, mcpMode);
Very good catch. The CANCTRL_REQOP
is 0xE0
, which is excluding the OSM bit 0x8
on CANCTRL[3]
Here is a picture from the mcp2515 datashet;
I can also confirm this fixes it, tested with an osciloscope.
@Loverboy7000 This would be a great feature to have in the master, is there anything I could do to help?
anyone can merge this?