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

Reduce the number of bytes over SPI for MCP2515Class::parsePacket() by up to 2.8x #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Aug 4, 2020

  1. Optimize MCP2515Class::parsePacket()

    1) Use the RX STATUS command instead of READ(CANINTF) to check availability of
       data to read. This reduces SPI usage for a simple "is data available" check
       from 3 bytes to 2.
    
    2) Use the READ RX BUFFER command to read the RXFn* registers as well as the
       received data. This requires doing only a single CS pull, and only N+6 bytes
       transferred over SPI. READ RX BUFFER also takes care of resetting the RXnIF
       flag.
    
    If my math is right, the old code needed N+6 readRegister() calls for a standard
    frame, and N+9 readRegister() calls for an extended frame, plus one
    modifyRegister() call to reset the RXnIF flag. Each readRegister() call requires
    a CS pull and transferring 3 bytes over SPI.
    
    For N = 8,
    - we now send 16 bytes over SPI vs 45 for a standard frame (>2.8x reduction!)
    - we now do just 2 CS pulls vs 16 for a standard frame (8x reduction!)
    timurrrr committed Aug 4, 2020
    Configuration menu
    Copy the full SHA
    828a145 View commit details
    Browse the repository at this point in the history