Skip to content

Race condition in interrupt handler causing failures when sending frames #12

@PinkPandaKatie

Description

@PinkPandaKatie

If MCP2515::intHandler() is called from an actual interrupt handler while another SPI transfer is in progress, it will try to initiate another SPI transfer, causing one or both transfers to fail.

There are two ways to work around this in client code:

  1. Surround every call to sendFrame(), Mode(), SetRXFilter(), etc. with noInterrupts()/interrupts()
  2. Do nothing except set a flag in the actual interrupt handler, then call MCP2515::intHandler later.

The first method works for me because I am not using any other SPI devices on the bus. If I were, then I would have to also disable interrupts for those operations. The second method works best if the flag can be polled frequently, otherwise received frames might get lost.

I'm not sure what the best solution would be for fixing the library, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions