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

Fix messages are not read in correct order #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mcp2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,6 @@ MCP2515::ERROR MCP2515::readMessage(const RXBn rxbn, struct can_frame *frame)

readRegisters(rxb->DATA, frame->data, dlc);

modifyRegister(MCP_CANINTF, rxb->CANINTF_RXnIF, 0);

return ERROR_OK;
}

Expand All @@ -668,10 +666,16 @@ MCP2515::ERROR MCP2515::readMessage(struct can_frame *frame)
ERROR rc;
uint8_t stat = getStatus();

if ( stat & STAT_RX0IF ) {
if ( stat & STAT_RX0IF && mcp2515_rx_index == 0) {
rc = readMessage(RXB0, frame);
if ( stat & STAT_RX1IF ) {
mcp2515_rx_index = 1;
}
modifyRegister(MCP_CANINTF, RXB[RXB0].CANINTF_RXnIF, 0);
} else if ( stat & STAT_RX1IF ) {
rc = readMessage(RXB1, frame);
mcp2515_rx_index = 0;
modifyRegister(MCP_CANINTF, RXB[RXB1].CANINTF_RXnIF, 0);
} else {
rc = ERROR_NOMSG;
}
Expand Down
2 changes: 2 additions & 0 deletions mcp2515.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ class MCP2515

uint8_t SPICS;

uint8_t mcp2515_rx_index = 0;

private:

void startSPI();
Expand Down