Building a CAN API for Arduino DUE

Got my prototype pcb's in and built one up.....seems to have passed ping-pong and skew testing (thanks for writing those tests btw) although i was using a short piece of cable and doing nothing else on the board. I used 233's with jumpers for 120ohm terminations, RS pin (10k on board), and loopback. I like the 233's w/loopback an example use would be if you are doing a project in which you have 2 CAN ports operating at two different baud rates, loopback lets you do some code testing...just my preference. Looking to do some OBD testing next, Feedback appreciated.

Found a painful issue putting the SPI stacking header on....because the DUE has a male header on it the SPI sits higher when stacked than the rest of the headers. This caused some pins to only have partial...of course because i was doing a CAN project in this occurred on the CAN pins! Not sure what i'm going to do about that, maybe for SPI use i have to recommend removal and swapping the DUE to a female stacking header as well. Feedback appreciated.

Hi all, CAN and arduino noob here...
Fisrt, thank you for the great job done, it always makes me happy seeing so much people involved in open projects :slight_smile:
I try to make up my mind for a project that uses CAN to talk to pioneer IP-Bus.
Am I restricted to SN65HVD234 transceivers in order to use this library? Or can I use a MCP2551-I/P (to be able to use a breadboard and eventually simple soldering)? Should I write a driver for it?
Thanks for the attention.

sanzoghenzo:
Am I restricted to SN65HVD234 transceivers in order to use this library? Or can I use a MCP2551-I/P (to be able to use a breadboard and eventually simple soldering)? Should I write a driver for it?
Thanks for the attention.

You can use a tuning fork, a ball of twine, and a pair of jumper cables if you want. The transceiver takes a TTL signal and turns it into a differential signal for canbus. Use whichever transceiver you want. The reason there is a driver file for the 234 transceiver is that it supports being turned on/off under MCU control. Otherwise the canbus code doesn't need to worry about what the transceiver does at all.

Having said that, the MCP2551 is a 5V device. The Due is a 3.3V device. This is not a match made in Heaven. The MCP2551 will probably accept the TX signal coming from the Due as it will be close to 3.3V and that should be enough to trigger the MCP chip. However, the MCP will be sending back a 5V RX signal and that's bad for your Due's health. You can fix that with a voltage divider but it's extra parts. So, yes, you can use it if you know what you're doing.

The 2551 can be put to sleep from the MCU (pin 8 = RS pulled HIGH), but I think you would need voltage shifting to make it work reliably with the due. Ciao, Lenny

thank you so much for the information. better stick with the SN65HVD234 then!

Hi folks,

Great work and thanks a lot to all involved! Just wanted to let you know that I finished my build on a proto-board and (surprise !) it worked from the beginning (at least the local loop-back tests).

Here's a pic of my version. It's going to be used in a car conversion (see http://s80ev.blogspot.com)

Note: Although it says 5V on the print, I'm running it on 3.3V only. :slight_smile:

So far so good :slight_smile:

Thanks for the tip about being able to do this Adder
CAN.global_send_transfer_cmd(CAN_TCR_MB0 | CAN_TCR_MB1 | CAN_TCR_MB2 | CAN_TCR_MB3 | CAN_TCR_MB4);

Worked perfectly!

Zabaat,

What are those nice robust-looking connectors on your last photo?

Ciao,
Lenny

Hi guys, thanks for all the effort in making this work!
I have been playing with CAN on the Due and have the basics figured out. I am struggling with one thing though... I can send and receive just fine but I need to receive a CAN message and assign its value (in HEX obviously) to a variable. I have been able to use incoming.data[] with some success but assume there is a better way to do this. I would like to assign all 8 bytes to a single variable but understand some limitations to that idea. Sorry for asking a noob question here but its only been a few weeks since I saw the arduino for the first time so I'm in a bit over my head :~ Just for fun I attached a pic of my breadboard setup and am also working toward manufacturing shields for this...
Thanks in advance for any help!

Hi there,

I did some research for CANopen OpenSource libraries and found the canfestival.org. That seams to have a very active community. canfestival also supports already AVR chips as noted on their "supported devices" page under CanFestival documentation.

I saw all the work you have already done for supporting CAN on the due. Great work, amazing.

Do you think it is feasible to integrate the canfestival into the Arduino IDE for Arduino Due and possibly also in Arduino Uno with the seeedstudio or sparkfun can shield?

Thx

Zabaat - is that a deutsch dtm series pcb mount connectors for use with the oem sealed enclosure they offer?

maxwest:
Do you think it is feasible to integrate the canfestival into the Arduino IDE for Arduino Due and possibly also in Arduino Uno with the seeedstudio or sparkfun can shield?

Hello maxwest,

As an integrator I could say Yes. Integrate canfestival (or any other third-party CANopen protocol like CanOpenNode, etc.) to Due or UNO should be feasible. The problem lies that between CAN bus and CANopen there is an in-construction bridge of missing layers to be built. So far, I'm not aware of any software (code) implementation that fills the gap. Again, it can be done and collin (reply #152) and me have made comments about this matter but let me explain in a dossier this thing.

CAN bus and CANopen (an other CANs) are OSI bus standards to communicate embedded control systems like MCUs between them without an intermediate host.

CAN bus is the lowest level link in the chain and it comprehends basically three layers or profiles.

  1. Physical layer. Implemented with a transceiver (SN65HVD234 in my design)
  2. Data Link layer. Implemented with a controller (inside SAM3X8E)
  3. Application Layer. Implemented with software (our CAN library)

Layers 1 and 2 are known as CAN itself.

CAN open is a higher level protocol. It comprehends the first two layers of CAN bus plus other layers above, as follows:

  1. Application Layer (non existent for DUE) - communication - I/O - drives -motion control - programmable devices
  2. Transport Layer (software-reliability, segmentation/desegmentation, error control).

Thus, it all about to generate the layers 3 and 4.

Having said this, now you know, broadly speaking, what it is required to complete the bridge and let the train goes.

There is another thing: Time. How much time can you afford to reconcile canfestival and Due? Right now I am trying to make our new Arduino CAN and EMAC libraries to run in a third-party board based on a SAM3X8C. This MCU has only 100 pins unlike the MCU of the Due SAM3X8E with 144 pins and even though they belong to the same family "X", I have to so some tweak on the current variant files (.cpp and .h) and pin_arduino.h. See that my case is your opposite case, I am integrating a third-party board with CAN library (you want integrate a third-party library with DUE or UNO). My integration is not a big deal given that the differences between both MCUs is minimal. In your case, I would recommend to visit the canfestival community and ask questions. I would recommend also that you start with UNO (AVR) and a CAN shield. I hope this helps you. Good luck!

hi,

I have on hands the tja1042t(High-speed CAN transceiver with Standby mode) http://www.nxp.com/documents/data_sheet/TJA1042.pdf

I like know if can I use this library to work with this uC, I see both datasheet (SN65HVD234 and TJA1042T -T/3) and both are the transceiver uC to CAN BUS.. the TJA1042T is only 5v and it can burn I/O on Due, for this I will use one circuit to make division, maybe 10k-10k get me 2.5v and this is OK to work.

I see on github the library name is SN56HVD234.c and .h is because this my question about use library on TJA1042.

tks all

You can try it. The transceiver is really fairly invisible to the way the library works. There is just a small amount of code to support an SN65HVD234. What happens is that the enable pin is set to enabled and the RS pin is controlled to manipulate the slope rate. But, you can easily make a board that does its own enabling and slope control and just not hook that stuff up to the Due at all. So, that brings me to whether you can use your transceiver. I suppose you could. It would probably accept the CANTX signal from the Due just fine. Then, as you said, you have to use a voltage divider or buffer chip to turn the 5V CANRX signal from the transceiver into a 3.3V signal to the Due. Chances are it would accept 2.5v. It isn't ideal but if you're just making something for yourself it makes sense to use whatever you happen to have on the bench.

Hi All,

Just for information, I made 2 shields : one is based on SN56HVD234, the other uses MCP2551.
I have run some basic tests and it seems to work fine for both.
Concerning the 5V aspect, I use Zener diode (3.3 or 3.6v) on the Rx pin, and it seems to work fine.

Hi guys,
I'm a bit in trouble.

First I started the CAN project with the original ASF example and did very minor changings. Unfortunately the CAN1 rcv interrupt routine doesn't get touched at all. I checked all my hardware with a oscilloscope and it seems it works fine. But no message reveiving, not even a error. Hrrmpfh.

Now I tried to attack with the functional Arduino example. I downloaded https://github.com/collin80/due_can, unzipped it, and copied it to C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\arduino-1.5.2\hardware\arduino\sam\libraries
Since the IDE did not accept the original name "due-can-master" while starting I named it DueCanMaster instead. When I try to compile I get a shipload of errors. Here are a few:

C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2/hardware/tools/g++arm_none_eabi/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=152 -D__SAM3X8E_ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON -IC:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/libsam -IC:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/ -IC:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/Device/ATMEL/ -IC:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\cores\arduino -IC:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\variants\arduino_due_x -IC:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\libraries\DueCanMaster C:\Users\Joachim\AppData\Local\Temp\build386121661864746555.tmp\Arduino_Due_CAN_Sample_1.cpp -o C:\Users\Joachim\AppData\Local\Temp\build386121661864746555.tmp\Arduino_Due_CAN_Sample_1.cpp.o
In file included from C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/Device/ATMEL/sam3xa/include/sam3x8e.h:260,
from C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/Device/ATMEL/sam3xa/include/sam3xa.h:44,
from C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/Device/ATMEL/sam3.h:59,
from C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/Device/ATMEL/sam.h:189,
from C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/libsam/chip.h:25,
from C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\cores\arduino/Arduino.h:34,
from C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\variants\arduino_due_x/variant.h:26,
from Arduino_Due_CAN_Sample_1.ino:7:
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:355: error: #elif without #if
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:655: error: #elif without #if
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:955: error: #elif without #if
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:1066: error: #endif without #if
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:1070: error: #endif without #if
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:1071: error: stray '\265' in program
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:1071: error: stray '\265' in program
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:1073: error: stray '\2' in program
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:1073: error: stray '\270' in program
C:\ARM_ARDUINO\1_5_2\arduino-1.5.2-windows\arduino-1.5.2\hardware\arduino\sam\system/CMSIS/CMSIS/Include/core_cm3.h:1073: error: stray '\210' in program

Why is that? Do I have to change some settings? I have no clue about github so I downloaded the zip file and unzipped it. Something wrong with this way?

Name the directory "due_can" just like the project name.

Hi Collin, renaming got me in the ballpark (is this yankee phrase suitable here? :slight_smile: and after additionally cleaning up the directories it compiles fine. I simply have to little experience with the IDE since all stuff I do with Atmel Studio. Thanks!

Here's a photo of my test hardware. DUE + 2x PIC 18F458.

I'm still researching the deeper sense of some registers since especially the PICs have a behaviour I don't always understand :wink:

hello, today came the SN65, TJA and the MCP CAN TRANSCEIVERS,

Before I make one board to use with this uC because I still having problens with breadboard assembly,
the picture foto(1) and Image(17) show this board... the top of image(17) show the SN65, I use Schematic of this post (page 3)

I try on with SN65 chip and work fine with DUE_CAN API, Thank You very much for this API

but I'm a very newbie on CAN Interface, I want talk with the board of the foto(2) but I don't know how,

I still reading forum and informations about CAN, and I conect the board direct on the can wire, the bard baud rate is 125KHZ (i change it on start ports) but no answare,

can anybody show one documentation to help me make this comunication.

thank you so much.

and thank you again for the CAN API,

foto (2).JPG