1

I am trying to read/send CanBus messages using a Arduino Due.

As of now I have used https://github.com/collin80/due_can library to setup my Can Bus interface.

I am using Vector Software CanAylzer to see what CAN message are being received.

This is where I have my issue. Although the CanAylzer software is being able to detect Can Messages on the line it gives be a Bit error on bit position 119. All the fields of relevance for me ID,Data etc seem to be reported fine.

Here is a snapshot of the CanAylzer Error Frame. Below is my Arduino code . Any help would be awesome. enter image description here

Here is the ino code:

// Arduino Due - CAN Sample 1
// Brief CAN example for Arduino Due
// Test the transmission from CAN0 Mailbox 0 to CAN1 Mailbox 0


#include <Arduino.h>
#include "variant.h"
#include "due_can.h"

#define TEST1_CAN_TRANSFER_ID    0x18FF0017 //random 29 bits
#define TEST1_CAN0_TX_PRIO       1
#define CAN_MSG_DUMMY_DATA       0xABC

// CAN frame max data length
#define MAX_CAN_FRAME_DATA_LEN   8

// Message variable to be send
uint32_t CAN_MSG_1 = 0;

void setup()
{

   // start serial port at 115200 bps:

   Serial.begin(115200);
   Serial.println("Program Started");

}

void loop(){

   CAN_FRAME frame1, frame2;
   // say what you got:
   Serial.print("Sent Value: ");
   Serial.println(CAN_MSG_1, DEC);

   // Initialize CAN0 and CAN1, baudrate is 250kb/s
   CAN.init(CAN_BPS_250K);
   CAN2.init(CAN_BPS_250K);

   //Initialize the definitions for the frames we'll be sending.
   //This can be done here because the frame never changes
   frame1.id = TEST1_CAN_TRANSFER_ID;
   frame1.length = MAX_CAN_FRAME_DATA_LEN;
   //Priority
   frame1.priority = 0;
   frame1.rtr = 1;
   //Below we set the 8 data bytes in 32 bit (4 byte) chunks
   //Bytes can be set individually with frame1.data.bytes[which] = something
   frame1.data.low = 0xAFAFAFAF;
   frame1.data.high = CAN_MSG_DUMMY_DATA;
   //We are using extended frames so mark that here. Otherwise it will just use
   //the first 11 bits of the ID set
   frame1.extended = 1;

   CAN.sendFrame(frame1);
   while (1) {
   }
}

Update

Ok so here are the printed(via serial port) values of various registers. I don't think it is a problem with the values in the registers. I have cross referenced these with the SAM3X/A (on the due) Micro-controller manual (chapter 41, pertaining to the CAN). The only one I am fishy about is the baudrate one.

Serial Port Initialized
******START OF LOOP ******
No of Sent frames: 1
<><><><><><><><><>><><><><>
CAN_SR:( Status Register)
Bits 3 | 2 | 1 | 0
     0 | 0 | 0 | 0

Bits 7 | 6 | 5 | 4
     0 | 0 | 0 | 0

Bits 11 | 10 | 9 | 8
      0 | 0  | 0 | 0

Bits 15 | 14 | 13 | 12
     0  | 0  | 0  | 0

Bits 19 | 18 | 17 | 16
     0  | 1  | 1  | 0

Bits 23 | 22 | 21 | 20
     1  | 0  | 1  | 0

Bits 27 | 26 | 25 | 24
     0  | 1  | 0  | 0

Bits 31 | 30 | 29 | 28
     0  | 1  | 0  | 0

<><><><><><><><><>><><><><>
#####END OF LOOP ######


Serial Port Initialized
******START OF LOOP ******
No of Sent frames: 1
<><><><><><><><><>><><><><>
CAN_MR: (Mode Register)
Bits 3 | 2 | 1 | 0
     0 | 0 | 0 | 1

Bits 7 | 6 | 5 | 4
     0 | 0 | 0 | 0

Bits 26 | 25 | 24
     0  | 0  | 0
<><><><><><><><><>><><><><>
#####END OF LOOP ######

******START OF LOOP ******
No of Sent frames: 4
<><><><><><><><><>><><><><>
CAN_MID7: (Message ID Register Mailbox 7)
Bits 3 | 2 | 1 | 0
     0 | 1 | 1 | 1

Bits 7 | 6 | 5 | 4
     0 | 0 | 0 | 1

Bits 11 | 10 | 9 | 8
     0  | 0  | 0 | 0

Bits 15 | 14 | 13 | 12
     0  | 0  | 0  | 0

Bits 19 | 18 | 17 | 16
     1  | 1  | 1  | 1

Bits 23 | 22 | 21 | 20
     1  | 1  | 1  | 1

Bits 27 | 26 | 25 | 24
     1  | 0  | 0  | 0

Bits 31 | 30 | 29 | 28
     0  | 0  | 1  | 1


Serial Port Initialized
******START OF LOOP ******
No of Sent frames: 1
<><><><><><><><><>><><><><>
CAN_ECR: (Error Count Register)
Bits 3 | 2 | 1 | 0
     0 | 0 | 0 | 0

Bits 7 | 6 | 5 | 4
     0 | 0 | 0 | 0

Bits 11 | 10 | 9 | 8
     0  | 0  | 0 | 0

Bits 15 | 14 | 13 | 12
     0  | 0  | 0  | 0

Bits 19 | 18 | 17 | 16
     0  | 0  | 0  | 0

Bits 23 | 22 | 21 | 20
     1  | 0  | 0  | 0

Bits 27 | 26 | 25 | 24
     0  | 0  | 0  | 0

Bits 31 | 30 | 29 | 28
     0  | 0  | 0  | 0

<><><><><><><><><>><><><><>
#####END OF LOOP ######

Lastly and most importantly in my opinion:

Serial Port Initialized
******START OF LOOP ******
No of Sent frames: 1
<><><><><><><><><>><><><><>
CAN_MSR7: (CAN Message Status Register Mailbox 7) 
Bits 3 | 2 | 1 | 0
     0 | 0 | 0 | 0

Bits 7 | 6 | 5 | 4
     0 | 0 | 0 | 0

Bits 11 | 10 | 9 | 8
      0 | 0  | 0 | 0

Bits 15 | 14 | 13 | 12
     0  | 0  | 0  | 0

Bits 19 | 18 | 17 | 16
     1  | 0  | 0  | 0

Bits 23 | 22 | 21 | 20
     0  | 0  | 0  | 0

Bits 27 | 26 | 25 | 24
     0  | 0  | 0  | 0

Bits 31 | 30 | 29 | 28
     0  | 0  | 0  | 0

<><><><><><><><><>><><><><>
#####END OF LOOP ######

and the Baud rate register

******START OF LOOP ******
No of Sent frames: 1
<><><><><><><><><>><><><><>
CAN_BR: 
Bits 3 | 2 | 1 | 0
     0 | 0 | 0 | 1

Bits 7 | 6 | 5 | 4
     0 | 0 | 0 | 1

Bits 11 | 10 | 9 | 8
     0 |  0  | 1 |  0

Bits 15 | 14 | 13 | 12
     0  | 0  | 1  | 0

Bits 19 | 18 | 17 | 16
     1  | 0  | 0  | 1

Bits 23 | 22 | 21 | 20
     0  | 0  | 1  | 0

Bits 27 | 26 | 25 | 24
     0  | 0  | 0  | 0

Bits 28
     0
<><><><><><><><><>><><><><>
#####END OF LOOP ######

You can find what all the register bits details on Atmel's website or leave some way for me to email the documentation to you.

Any Help would be much appreciated!

Update 2:

I have attached 2 different Oscilloscope readings and deconstructed the entire binary representation of the Can message manually. Furthermore I calculated the associated CRC's of the two different messages, and then compared them to the ones the hardware created and found them(hardware ones) to be incorrect. I have provided a link to Google Drive where the results from the Oscilloscope can be found.

PS: the messages I used had in one 7 A's(hex, i.e 28bits) for the ID and 16 A's for the Data field. The second one had 7 C's for the Id and 16 C's for the Data field.

Both are 2.0B can extended frames.enter image description hereenter image description here

  • Looks like a CRC error. But the CRC calculation is done by hardware, so neither your fault nor the library's. Do you see a chance of monitoring the CAN line? If I'm not completely wrong, CRC for this frame should be 0x5F88 – mic Sep 9 '14 at 11:25
  • @mic the CANalyzer(pictured above) does that for me. I know its a problem with the CRC but why? And how do I fix it? – SeahawksRdaBest Sep 10 '14 at 16:16
  • Good question! :-) That Vector stuff is not perfect, but the tools (and especially the prices) are made for professional use. The only thing I can imagine at the moment is a slightly different baudrate and/or an improper tq setting in your CANalyzer. What happens if you play a little bit with the sampling point? And again: Do you have a chance to look directly at the CAN line (e.g. using a scope)? It would be interesting to know what the Arduino really transmits. – mic Sep 10 '14 at 21:09
  • @mic how do I check the tq settings? I have checked all the registers on the hardware level as well they seem to have the correct information. – SeahawksRdaBest Sep 25 '14 at 22:42
  • @mic also have you used vector software before? – SeahawksRdaBest Sep 25 '14 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.