Skip to content

Commit dd256c1

Browse files
committed
PR autowp#46 opened on Sep 12, 2020 by jxltom : Fix messages are not read in correct order
1 parent a8245ac commit dd256c1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

mcp2515.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,6 @@ MCP2515::ERROR MCP2515::readMessage(const RXBn rxbn, struct can_frame *frame)
671671

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

674-
modifyRegister(MCP_CANINTF, rxb->CANINTF_RXnIF, 0);
675-
676674
return ERROR_OK;
677675
}
678676

@@ -681,10 +679,14 @@ MCP2515::ERROR MCP2515::readMessage(struct can_frame *frame)
681679
ERROR rc;
682680
uint8_t stat = getStatus();
683681

684-
if ( stat & STAT_RX0IF ) {
682+
if ( stat & STAT_RX0IF && mcp2515_rx_index == 0 ) {
685683
rc = readMessage(RXB0, frame);
684+
if ( stat & STAT_RX1IF ) mcp2515_rx_index = 1;
685+
modifyRegister(MCP_CANINTF, RXB[RXB0].CANINTF_RXnIF, 0);
686686
} else if ( stat & STAT_RX1IF ) {
687-
rc = readMessage(RXB1, frame);
687+
rc = readMessage( RXB1, frame );
688+
mcp2515_rx_index = 0;
689+
modifyRegister(MCP_CANINTF, RXB[RXB1].CANINTF_RXnIF, 0);
688690
} else {
689691
rc = ERROR_NOMSG;
690692
}

mcp2515.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ class MCP2515
449449
uint8_t SPICS;
450450
uint32_t SPI_CLOCK;
451451
SPIClass * SPIn;
452+
uint8_t mcp2515_rx_index = 0;
452453

453454
private:
454455

0 commit comments

Comments
 (0)