Go Down

Topic: Building a CAN API for Arduino DUE (Read 357019 times) previous topic - next topic


Mar 07, 2014, 02:21 am Last Edit: Mar 07, 2014, 02:23 am by jspobuk Reason: 1
Finally finished my shield.  The through holes are to give access to the header pins in the middle of the board.  I think the next version will just have the pins go through.  The header sockets were a little annoying to solder.  Solder paste does amazing things with surface mount chips.  No more frustrating solder joint problems.   Now just waiting for the engine to arrive.  :D


Mar 10, 2014, 01:34 pm Last Edit: Mar 10, 2014, 05:38 pm by noop Reason: 1
Love what you guys are doing here!
I have a very newbie question. I wonder if someone can show me how to filter for just the ECU?
It seems that what I am doing is not the right thing.

I want to read trouble codes and I keep getting lost somewhere.
I can TX 0x7DF with 03 parameter but RX is my downfall.

CAN.setRXFilter(filter, 0, 0, false); //gets way too much of everything

I try the following two lines and that's where I go wrong:

CAN.setRXFilter(filter, 0x7E8, 0, false);

CAN.setRXFilter(filter, 0, 0x7E8, false);

I just don't get how to set the filter.


setRXFilter has two forms:

int setRXFilter(id, mask, extended);


int setRXFilter(mailbox, id, mask, extended);

You seem to be using the second type that allows you to explicitly set which mailbox you are talking about.

In order to properly filter a frame you need to set reasonable values for both id and mask. The incoming frames are AND with the mask and then compared to the id. So, if you need to accept only frames with 0x7E8 then you can set the mask to 0x7FF which forces all frames to exactly match the id. Thus, your call would be:

CAN.setRXFilter(filter, 0x7E8, 0x7FF, false);


Thank you for that answer. Filtering is little clearer for me now.

I will test this in a couple of days.

Mike M


I'm trying to send CAN frames from one Due compatible board to another one using Collin80's library.  The sending part works fine and I can see byte traffic with a scope all the way up to the RX TX side of the transceiver on the receiving board.  However, rx_avail() never returns true on the receiving side.  I'm using the CAN_TrafficSnooper example sketch that should not filter any messages and print out everything to the serial console.

Any debugging hints or ideas about what might be going wrong?

As a side question: what is the
Code: [Select]
#define TEST1_CAN0_TX_PRIO       15
line in the example sketches?  I don't see it used anywhere.


Hello Mike,
Have you tried the two can modules (CAN0/CAN1) in the same DUE as initially intended in the examples? I tested the EchoTest, ExtendedPingPong and TrafficSnooper and they worked OK on the same original DUE (also with Taijiuino). I haven't tried with two DUEs but Collin's examples should work. It is just about to be careful with the interconnection of the modules. I.e. CAN0 on Due1 with CAN1 on Due2 or CAN1 on Due1 with CAN0 on Due2...or depending on your code, therefore, it would be good if you post your code if differs from the original Collin's examples.

Regards, Palliser   


I need to get the most obvious two points out of the way first:

1. Are you using some sort of CANBus shield which has transceivers on it? You really do need transceivers. If you do have a board then it would help to know if it was something you made or something you bought (and if so, which board did you buy?)

2. Are the canbus wires terminated? A lot of shields are going to have at least selectable termination but you need there to be 60 ohms between CANH and CANL. This should take the form of a 120 ohm resistor at each end of the bus.

Even with the proper transceivers you will not get a signal through between two devices without some termination. A lot of times you can get away with just one 120 or 100 ohm resistor on one end if the link is short. But, 60 ohms is proper.

Mike M

Mar 13, 2014, 04:27 pm Last Edit: Mar 13, 2014, 07:18 pm by Mike M Reason: 1
Thanks for the replies.

I've made two AT91SAM3X8E based Arduino-compatible boards working off the Due schematics.  I'm using two TI ISO1050 isolated CAN transceivers (datasheet).  Since these transceivers need to be powered from both sides I have one board powering the transceiver of the other board.  I've attached a partial schematic below.

I do own an official Due.  I'll try wiring up transceivers from CAN0 to CAN1 on the Due and see if the PingPong example works.

UPDATE: The breadboarded version using two of the ISO1050 transceivers and one Arduino Due runs the CAN_EchoTest and CAN_ExtendedPingPong examples correctly.  I'll keep looking through my hardware, but let me know if there's something I could be missing.


Mar 15, 2014, 02:51 am Last Edit: Mar 15, 2014, 02:54 am by Palliser Reason: 1
Hello Mike,

It might be considered a note on page 4 of the TI ISO1050 specs doc:

"TXD is very weakly internally pulled up to VCC1. An external pull up resistor should be used to make sure that TXD is biased to recessive (high) level to avoid issues on the bus if the microprocessor doesn't control the pin and TXD floats. TXD pullup strength and CAN bit timing require special consideration when the device is used with an open-drain TXD output on the microprocessor's CAN controller. An adequate external pullup resistor must be used to ensure that the TXD output of the microprocessor maintains adequate bit timing input to the input on the transceiver".


Long overDUE and probably rushed, here is an OBD2 /free-running CAN library I've been picking away at.

I'll apologize in advance for:
-developing with the old due_can libraries Collin80 developed and not porting it over to the newer yet
- it's probably slow and I haven't taken full advantage of the HW (only using one CAN mailbox for example)
- any code conventions I probably don't follow, I did put as much green as a plane flight would allow for
- it's only been tested on one vehicle (see logs), toyota w/11-bit ID's

See the readme on github and the examples for OBD2 implementaitons and free-running CAN

Hope this moves the needle a bit. I should have some upcoming practical uses for this code that will force me to work on it a bit more.
Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields


Hello Dan and thank you very much for share your OBD library for Arduino DUE. Nice job (an a lot of work). I think it is one of the first practical automotive applications based in the due_can library. It really moves the needle (up to 99 KPH!)
I have one question: did you use the pins 6 (CANH) and 14(CANL) in the OBD connectors like I showed in my reply #38?
Regards. -P


I have a pre-made OBD cable for CAN ( i think from obd2cables.com)....While i didn't check it would have to be 6 and 14 in order to work (CANH, CANL) .
Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields


answer to question.
Customers can also look on the box label for the 2-character Environment Category (E-Cat) Code. If it starts with "G" (G3, G4, etc), the box contains Green compatible parts (E-Cat Codes were added to boxes beginning on June 1st, 2004.

Thank you for the links and info.
The page with the transceiver chip has different ones.
Which one do I need and whats the difference between these ?
SN65HVD234DG4  (G4 means super GREEN part, for sure, above may not be.. )   R suffix are reel parts.

Can you recommend a Arduino bread board start kit also ?

I don't have any idea why places like Mouser and Digikey do that... They're the same part. Sometimes they have funny stuff like that where you have the same part with very slightly different part numbers varying only in suffix. Perhaps there is a slight difference of some sort but I don't know what it is. Chances are either would work fine.

As for an Arduino bread board, I did recommend one. The schmartboard is a breadboard with 1.27mm spots for chips that fits on an arduino.


Apr 02, 2014, 04:19 pm Last Edit: Apr 02, 2014, 04:35 pm by MorgKrig Reason: 1
I'd like to build up a CAN Receiver with the Arduino DUE just to receive data.
Is there anywhere a solution or a project like that?

Is the CAN API for the DUE rdy for use?

Thx for your help!


MorgKrig you may want check out my acquisition lib on github I have an rx example in there for free running 11bit messages. Could certainly use more testing.
Dan - www.togglebit.net - Arduino DUE proto shields - Arduino DUE CAN shields

Go Up