Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Open
MatiasJHZ opened this issue May 6, 2025 · 0 comments

Comments

@MatiasJHZ
Copy link

MatiasJHZ commented May 6, 2025

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant