Problems reading mixed extended and standard ID frames on CAN bus - Arduino Due

Hi guys,
I'm pretty new to Arduino and I'm currently working on a CAN gateway using an Arduino Due Board and 2 Waweshare SN65HVD230 boards.

On one CAN port I should read both extended and standard ID can frames but currently I'm facing a problem.
If I send from an external device a single CAN frame with extended ID 0x1BFEA09 using the due_can library I can read the frame and its ID correctly.
If I send a second frame with extended ID 0x80 I can read both messagges and their IDs correctly.

The problems comes out when I send to Arduino CAN port:

  • 0x1BFEA09 frame with extended ID format
  • 0x80 frame with standard ID format

In the last case, from the command canframe.id I get, for the extended frame, the ID 1BC0000.

I also tried to put a filter on one of the mailboxes to receive on that mailbox only the 0x1BFEA09 extended ID and put a callback function on this mailbox: in this case the callback function works correctly, meaning that from an "hardware" point of view the message with extended ID 0x1BFEA09 is received correctly.

I also noticed that 1BC0000 is the number you get only considering the bits from 18 to 28 of 0x1BFEA09 (so putting bits from 0 to 17 to 0), that makes me think that there is somewhere in the libraries a mismatch between the 11 bits of standard IDs and 29 bits of extended IDs.

Has anyone experienced the same problem?
Any suggestion to where to look in the .h and .ccp files of the due_can library to see if it can be a software problem?

Thanks, regards

Gabriele

There is a tutorial for using Can_DUE library from EVTV Motor Werks:

http://media3.ev-tv.me/CAN%20Due2.2%20User%20Manual.pdf

Hi ard_newbie,
thanks for your suggestion but my problem isn't using the library.
Writing and reading only standard id frames I've been able to run the library without problems.

My problem is reading on the same CAN port a mix of standard and extended id frames.

Regards

Gabriele

gabriele_vandi:
Any suggestion to where to look in the .h and .ccp files of the due_can library to see if it can be a software problem?

Please confirm which .h file you are including in your sketch

Did you read this in the tutorial (around page 26 of the .pdf):

Can0.watchFor();

This command allows ALL messages to be accepted. But better, it actually sets up one mailbox for standard frames, and a second mailbox for extended frames. All messages of either standard or extended frames are then accepted.

You can select some ID or ID + mask with Can0.watchFor(0x740);Can0.watchFor(0x620, 0x7F0);
Or Can0.watchForRange(0x620, 0x64F); to select a range of IDs.

sherzaad:
Please confirm which .h file you are including in your sketch

I’m including due_can.h and variant.h.

A small update: I’ve done further testing and experienced another strange behaviuor.
I’m now sending 5 CAN frames in the following order:

  • standard ID 0x79
  • standard ID 0x80
  • extended ID 0x1BFEA05
  • extended ID 0x1BFEA06
  • extended ID 0x1BFEA07

In this case I read correctly the first two standard ID frames.
I don’t read correctly the first extended id frame (so 0x1BFEA05 which is read as 0x1BC0000).
Instead I read correctly the 2nd and 3rd extended ID frames (so 0x1BFEA06 and 0x1BFEA07).

So apparently there’s a problem when moving from standard to extended id for the first frame

ard_newbie:
Did you read this in the tutorial (around page 26 of the .pdf):

Can0.watchFor();

This command allows ALL messages to be accepted. But better, it actually sets up one mailbox for standard frames, and a second mailbox for extended frames. All messages of either standard or extended frames are then accepted.

You can select some ID or ID + mask with Can0.watchFor(0x740);Can0.watchFor(0x620, 0x7F0);
Or Can0.watchForRange(0x620, 0x64F); to select a range of IDs.

Many thanks again for the suggestion!
I've set Mailboxes 0 to 5 to read standard ID frames and mailboxes 6 to 7 to read extened id frames and now the 5 frames of my previous message are read correctly!

Thanks again for your tips, you've been very helpful!

Regards

Gabriele