arduino-mcp2515 icon indicating copy to clipboard operation
arduino-mcp2515 copied to clipboard

Added support for One-Shot Mode (OSM)

Open DeltaC6 opened this issue 3 years ago • 7 comments

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.

DeltaC6 avatar Aug 03 '21 18:08 DeltaC6

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.

DeltaC6 avatar Aug 04 '21 07:08 DeltaC6

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...

Loverboy7000 avatar Aug 05 '21 18:08 Loverboy7000

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

DeltaC6 avatar Aug 05 '21 20:08 DeltaC6

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

dextercai avatar Jun 14 '22 09:06 dextercai

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);

igorok107 avatar Sep 05 '22 07:09 igorok107

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);

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;

image

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?

TinyDinosaur avatar Feb 27 '23 21:02 TinyDinosaur

anyone can merge this?

lsdlsd88 avatar Nov 03 '23 14:11 lsdlsd88