Skip to content

reading only 3 messages. Maybe rx buffers are full? can't find function to clear out rx buffers #119

Closed
@MatiasJHZ

Description

@MatiasJHZ

Hello,

I am using the the CAN write and CAN read examples provided with this library, using an Arduino UNO in both ends. The transmitter is continously sending a constant message, and the receiver is able to just receive 3 messages and then nothing.

Is the CAN read example code incomplete? do I need to clear the buffers to receive more messages?

The datasheet of the MCP2515 says the following:

When a message is moved into either of the receive
buffers, the appropriate RXnIF bit (CANINTF) is set.
This bit must be cleared by the MCU in order to allow a
new message to be received into the buffer. This bit
provides a positive lockout to ensure that the MCU has
finished with the message before the MCP2515
attempts to load a new message into the receive buffer.

I try to clear that bit by using the function: mcp2515.clearInterrupts();, however that doesn' work.

Here is my code inside the void loop:

`
void loop() {
if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {
Serial.print(canMsg.can_id, HEX); // print ID
Serial.print(" ");
Serial.print(canMsg.can_dlc, HEX); // print DLC
Serial.print(" ");

for (int i = 0; i<canMsg.can_dlc; i++)  {  // print the data
  Serial.print(canMsg.data[i],HEX);
  Serial.print(" ");
}

Serial.println();      

}
else if(mcp2515.readMessage(&canMsg) == MCP2515::ERROR_FAIL){
Serial.println("Error reading CAN message");
}
else if(mcp2515.readMessage(&canMsg) == MCP2515::ERROR_NOMSG){
Serial.println("NO MSG");
mcp2515.clearInterrupts();
delay(1000);
}
else{
uint8_t stat = mcp2515.getStatus();
Serial.println(stat);
delay(1000);
}
}

`

Thanks for your help,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions