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

Stops to receive after send #51

Open
Dimitar-88 opened this issue Nov 26, 2020 · 0 comments
Open

Stops to receive after send #51

Dimitar-88 opened this issue Nov 26, 2020 · 0 comments

Comments

@Dimitar-88
Copy link

Dimitar-88 commented Nov 26, 2020

Hi Colin.
I have an odd issue with the library. I did basically modify the example: Can_SendingTest
I have removed all CAN1 related information and i have added the function to print the output message.
The issue is when it sends data 2 times it suddenly stops receiving data in.

The set up is the following Arduino UNO with mcp2515 sending some data.
Then Arduino Due gets it via SN65HVD230 module.

The first thing is the receive buffer seems to not be cleared after read. so i get rapidly same thing that got in once.
Second thing is that after a few sends the receiving stops stops.
Last problem i have is that the sent data can't be read on my Uno it is like it was never sent out.

Here is the modified sketch :
#include "variant.h"
#include <due_can.h>

//Leave defined if you use native port, comment if using programming port
//#define Serial SerialUSB

void setup()
{

Serial.begin(115200);

// Initialize CAN0 and CAN1, Set the proper baud rates here
Can0.begin(CAN_BPS_500K);

Can0.watchFor();
}

void printFrame(CAN_FRAME &frame) {
Serial.print("ID: 0x");
Serial.print(frame.id, HEX);
Serial.print(" Len: ");
Serial.print(frame.length);
Serial.print(" Data: 0x");
for (int count = 0; count < frame.length; count++) {
Serial.print("0x");
if(frame.data.bytes[count]<10)
Serial.print("0");
Serial.print(frame.data.bytes[count], HEX);
Serial.print(" ");
}
Serial.print("\r\n");
}

void sendData()
{
CAN_FRAME outgoing;
outgoing.id = 0x688;
outgoing.extended = false;
outgoing.priority = 4; //0-15 lower is higher priority
outgoing.length = 8;
outgoing.data.byte[0] = 0x55;
outgoing.data.byte[1] = 0x11;
outgoing.data.byte[2] = 0xDD;
outgoing.data.byte[3] = 0x33;
outgoing.data.byte[4] = 0x44;
outgoing.data.byte[5] = 0x55;
outgoing.data.byte[6] = 0x66;
outgoing.data.byte[7] = 0x77;

Can0.sendFrame(outgoing);

printFrame(outgoing);
}

void loop(){
CAN_FRAME incoming;
static unsigned long lastTime = 0;

if (Can0.available() > 0) {
Can0.read(incoming);
printFrame(incoming);
}

if ((millis() - lastTime) > 1000)
{
lastTime = millis();
sendData();
}
}

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