Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for One-Shot Mode (OSM) #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DeltaC6
Copy link

@DeltaC6 DeltaC6 commented Aug 3, 2021

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.

Copy link

@Loverboy7000 Loverboy7000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 176 needs to be ==

@DeltaC6
Copy link
Author

DeltaC6 commented Aug 4, 2021

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.

@Loverboy7000
Copy link

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

@DeltaC6
Copy link
Author

DeltaC6 commented Aug 5, 2021

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

Copy link

@haloiceant haloiceant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had a go at implementing this update. it compiles just fine, but does not place the MCP2515 into one shot mode.

the code i am using will command the mcp2515 to transmit a can message when user inputs "1" in serial monitor.

with OSM disabled, this should cause the message to be retransmitted until an acknowledge bit is received. with OSM enabled, this should cause the message to be only transmitted once.

i have attached oscilloscope to CANL and have screen shots of both scenarios attached.

if enableOSM works properly, it should only transmit one message. unfortunatley, it is identical to disableOSM behavior.

disableOSM
enableOSM

@dextercai
Copy link

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

@igorok107
Copy link

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

@TinyDinosaur
Copy link

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?

@lsdlsd88
Copy link

lsdlsd88 commented Nov 3, 2023

anyone can merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants