Skip to content

Incorrect rtrBit checking in MCP_CAN::mcp2515_read_canMsg() method implementation #63

@sfyang

Description

@sfyang

Under current implementation, the RTR bit checking code for the MCP_CAN::mcp2515_read_canMsg() method implementation is done as following:

spi_readwrite(buffer_load_addr);
// mcp2515 has auto-increment of address-pointer
for (i = 0; i < 4; i++) tbufdata[i] = spi_read();

*rtrBit=(tbufdata[3]&0x08 ? 1 : 0 );

According to the datasheet of MCP2515 (please also refer to #62 for the details), the RTR bit is the 5th bit (bit 4) in the RXBnSIDL register. However, since buffer_load_addr is either MCP_READ_RX0 or MCP_READ_RX1. which points to RXBnSIDH register, tbufdata[3], the 4th byte of 4-byte consecutive read, is RXBnEID0 rather than RXBnSIDL, and the bit mask 0x08 is also incorrect either. This makes this RTR bit checking code returns completely incorrect result.

If #62 has been fixed, the proper implementation would be something as the following:

*rtrBit=(tbufdata[MCP_SIDL]&MCP_RTR_MASK ? 1 : 0 );

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