ArduinoGeneral

CAN BUS Shield DFR0370 performance

userHead yonghan007 2016-11-15 15:22:09 1925 Views3 Replies
Hi,
I'm using arduino uno and DFR0370 to log CAN Bus.
To measure the DFR0370 performance, I sent CAN message with short period time.
Receive mode was interrupt.
From 10msec to 2msec, it works well. No missing any message.
But, after send CAN message with 1msec period, it cannot receive continuously.
I measured buffer reading time by using "micros()", it was about 1.7msec.
Modifying SPI clock divider to 2 is little bit better, buffer reading time was 1.5msec
I would like to measure every CAN messages without missing.
Below is my full code. Please, give me your hand.

('', '
#include <SPI.h>
#include "df_can.h"

const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin

unsigned char len = 0;
unsigned char buf[8];
char str[20];
int msgID = 0;
unsigned long time[255];
unsigned int timeindex = 0;
String sendmsg;
unsigned int testtimer[2];

void setup()
{
String reportString = "Time\tID\tLn\tD0\tD1\tD2\tD3\tD4\tD5\tD6\tD7";
Serial.begin(250000);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
do {
CAN.init(); //must initialize the Can interface here!
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");
delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}
}while(count--);
//Serial.println(reportString);
//SPI.setClockDivider(SPI_CLOCK_DIV2);
attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
}

void MCP2515_ISR()
{
time[timeindex] = micros();
if(timeindex==255)
{
timeindex=255;
}
else
{
timeindex++;
}
}

void loop()
{
if(timeindex > 0)
{ // check if get data
testtimer[0]=micros();
// iterate over all pending messages
// If either the bus is saturated or the MCU is busy,
// both RX buffers may be in use and after having read a single
// message, MCU does clear the corresponding IRQ conditon.
while (CAN_MSGAVAIL == CAN.checkReceive())
{
// read data, len: data length, buf: data buf
CAN.readMsgBuf(&len, buf);
sendmsg=String(time[timeindex-1])+"\t"+String(CAN.getCanId(),HEX)+"\t"+String(len)+"\t";
// print the data
for(int i = 0; i<len; i++)
{
sendmsg+=String(buf[i],HEX)+"\t";
}
//Serial.println(sendmsg);
//for(int i=0;i<timeindex;i++)Serial.print(String(time[i])+"/");
//Serial.print(String(timeindex)+"/");
}
timeindex--; // clear flag
time[timeindex]=0;
testtimer[1]=micros();
Serial.println(String(testtimer[1]-testtimer[0]));
}
else
{
}
}
[/code]')
2016-11-24 18:41:44 Hi yonghan007,

I got a reply from my team, they said according to your problems, there are two possible reasons:the amount of data transferred is beyond the length of a cycle; receiving controller processing speed can't keep up.

And we did a test referring to our wiki-https://www.dfrobot.com/wiki/index.php/CAN-BUS_Shield_V2_(SKU:_DFR0370)#Basic_CAN_BUS_Receiving_and_sending_function_.28receiving:_polling_mode.29

Set the time delay 1ms between sending instructions, the receiver does not appear the phenomenon of missing data. So I'm just guessing is there a possibility that your data length is longer than the length of a cycle?

Any problem please let me know, then I will give a feedback to our team. Hope we can solve your problem. :)
userHeadPic Wendy.Hu
2016-11-17 16:18:50 Wendy,

There is no possibility that cycle is less than 1ms. The fastest message has 10msec cycle time.
But, I want to get as many messages as possible for logging at real vehicle. In this case, many messages come into CAN buffer within 1 msec.
For example, 5 messages with 10msec cycle time, 10 messages with 20msec cycle time,...etc.

In my oppinion, it depends on Arduino, not CAN Bus shield.
userHeadPic yonghan007
2016-11-16 16:04:13 Hi Sir,

Sorry, I am not very clear about the CAN BUS, there is possibility that its cycle is less than 1ms? I have gave a feedback to our team, any response I will reply you immediately.
userHeadPic Wendy.Hu