CAN Bus Shield V2.0 with Arduino Due?

Hello,
Does CAN Bus Shield V2.0 work with Arduino Due?
I am currently using it with an Arduino Mega, but am contemplating switching to Arduino Due due to a faster processor and more memory.

There should be no problems. I haven’t tested Arduino DUE.

In the Arduino IDE 1.8.12 I installed the Arduino DUE board using the board manager, but when I try to compile the CAN Receive Example I get errors.
Any idea what is wrong?

C:\Users\KLARICG\Downloads\arduino-1.8.12\arduino-builder -dump-prefs -logger=machine -hardware C:\Users\KLARICG\Downloads\arduino-1.8.12\hardware -hardware C:\Users\KLARICG\AppData\Local\Arduino15\packages -tools C:\Users\KLARICG\Downloads\arduino-1.8.12\tools-builder -tools C:\Users\KLARICG\Downloads\arduino-1.8.12\hardware\tools\avr -tools C:\Users\KLARICG\AppData\Local\Arduino15\packages -built-in-libraries C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries -libraries C:\Users\KLARICG\Documents\Arduino\libraries -fqbn=arduino:sam:arduino_due_x_dbg -ide-version=10812 -build-path C:\TEMP\arduino_build_550301 -warnings=default -build-cache C:\TEMP\arduino_cache_901928 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arm-none-eabi-gcc.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.bossac.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino -prefs=runtime.tools.bossac-1.6.1-arduino.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino -verbose C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries\MCP_CAN\examples\CAN_receive\CAN_receive.ino
C:\Users\KLARICG\Downloads\arduino-1.8.12\arduino-builder -compile -logger=machine -hardware C:\Users\KLARICG\Downloads\arduino-1.8.12\hardware -hardware C:\Users\KLARICG\AppData\Local\Arduino15\packages -tools C:\Users\KLARICG\Downloads\arduino-1.8.12\tools-builder -tools C:\Users\KLARICG\Downloads\arduino-1.8.12\hardware\tools\avr -tools C:\Users\KLARICG\AppData\Local\Arduino15\packages -built-in-libraries C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries -libraries C:\Users\KLARICG\Documents\Arduino\libraries -fqbn=arduino:sam:arduino_due_x_dbg -ide-version=10812 -build-path C:\TEMP\arduino_build_550301 -warnings=default -build-cache C:\TEMP\arduino_cache_901928 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arm-none-eabi-gcc.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.arm-none-eabi-gcc-4.8.3-2014q1.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1 -prefs=runtime.tools.bossac.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino -prefs=runtime.tools.bossac-1.6.1-arduino.path=C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino -verbose C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries\MCP_CAN\examples\CAN_receive\CAN_receive.ino
Using board 'arduino_due_x_dbg' from platform in folder: C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12
Using core 'arduino' from platform in folder: C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12
Detecting libraries used...
"C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10812 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/libsam" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/CMSIS/Include/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/Device/ATMEL/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\cores\\arduino" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\variants\\arduino_due_x" "C:\\TEMP\\arduino_build_550301\\sketch\\CAN_receive.ino.cpp" -o nul
Alternatives for mcp_can.h: [MCP_CAN]
ResolveLibrary(mcp_can.h)
  -> candidates: [MCP_CAN]
"C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10812 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/libsam" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/CMSIS/Include/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/Device/ATMEL/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\cores\\arduino" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\variants\\arduino_due_x" "-IC:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\libraries\\MCP_CAN" "C:\\TEMP\\arduino_build_550301\\sketch\\CAN_receive.ino.cpp" -o nul
Alternatives for SPI.h: [SPI@1.0]
ResolveLibrary(SPI.h)
  -> candidates: [SPI@1.0]
"C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10812 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/libsam" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/CMSIS/Include/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/Device/ATMEL/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\cores\\arduino" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\variants\\arduino_due_x" "-IC:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\libraries\\MCP_CAN" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\libraries\\SPI\\src" "C:\\TEMP\\arduino_build_550301\\sketch\\CAN_receive.ino.cpp" -o nul
"C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10812 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/libsam" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/CMSIS/Include/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/Device/ATMEL/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\cores\\arduino" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\variants\\arduino_due_x" "-IC:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\libraries\\MCP_CAN" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\libraries\\SPI\\src" "C:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\libraries\\MCP_CAN\\mcp_can.cpp" -o nul
"C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10812 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/libsam" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/CMSIS/Include/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/Device/ATMEL/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\cores\\arduino" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\variants\\arduino_due_x" "-IC:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\libraries\\MCP_CAN" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\libraries\\SPI\\src" "C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\libraries\\SPI\\src\\SPI.cpp" -o nul
Generating function prototypes...
"C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10812 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/libsam" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/CMSIS/Include/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/Device/ATMEL/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\cores\\arduino" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\variants\\arduino_due_x" "-IC:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\libraries\\MCP_CAN" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\libraries\\SPI\\src" "C:\\TEMP\\arduino_build_550301\\sketch\\CAN_receive.ino.cpp" -o "C:\\TEMP\\arduino_build_550301\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\TEMP\\arduino_build_550301\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -c -g -Os -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=10812 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/libsam" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/CMSIS/Include/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\system/CMSIS/Device/ATMEL/" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\cores\\arduino" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\variants\\arduino_due_x" "-IC:\\Users\\KLARICG\\Downloads\\arduino-1.8.12\\libraries\\MCP_CAN" "-IC:\\Users\\KLARICG\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\sam\\1.6.12\\libraries\\SPI\\src" "C:\\TEMP\\arduino_build_550301\\sketch\\CAN_receive.ino.cpp" -o "C:\\TEMP\\arduino_build_550301\\sketch\\CAN_receive.ino.cpp.o"
In file included from C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3xa/include/sam3xa.h:44:0,

                 from C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3.h:59,

                 from C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam.h:198,

                 from C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/libsam/chip.h:25,

                 from C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:42,

                 from C:\TEMP\arduino_build_550301\sketch\CAN_receive.ino.cpp:1:

C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3xa/include/sam3x8e.h:478:29: error: expected ')' before '*' token

 #define CAN0       ((Can    *)0x400B4000U) /**< \brief (CAN0      ) Base Address */

                             ^

C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries\MCP_CAN\examples\CAN_receive\CAN_receive.ino:13:9: note: in expansion of macro 'CAN0'

 MCP_CAN CAN0(10);                               // Set CS to pin 10

         ^

C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\system/CMSIS/Device/ATMEL/sam3xa/include/sam3x8e.h:478:29: error: expected ')' before '*' token

 #define CAN0       ((Can    *)0x400B4000U) /**< \brief (CAN0      ) Base Address */

                             ^

C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries\MCP_CAN\examples\CAN_receive\CAN_receive.ino:13:9: note: in expansion of macro 'CAN0'

 MCP_CAN CAN0(10);                               // Set CS to pin 10

         ^

C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries\MCP_CAN\examples\CAN_receive\CAN_receive.ino: In function 'void setup()':

CAN_receive:21:11: error: request for member 'begin' in '1074479104u', which is of pointer type 'Can*' (maybe you meant to use '->' ?)

   if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)

           ^

CAN_receive:26:8: error: request for member 'setMode' in '1074479104u', which is of pointer type 'Can*' (maybe you meant to use '->' ?)

   CAN0.setMode(MCP_NORMAL);                     // Set operation mode to normal so the MCP2515 sends acks to received data.

        ^

C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries\MCP_CAN\examples\CAN_receive\CAN_receive.ino: In function 'void loop()':

CAN_receive:37:10: error: request for member 'readMsgBuf' in '1074479104u', which is of pointer type 'Can*' (maybe you meant to use '->' ?)

     CAN0.readMsgBuf(&rxId, &len, rxBuf);      // Read data: len = data length, buf = data byte(s)

          ^

Using library MCP_CAN in folder: C:\Users\KLARICG\Downloads\arduino-1.8.12\libraries\MCP_CAN (legacy)
Using library SPI at version 1.0 in folder: C:\Users\KLARICG\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\SPI 
exit status 1
request for member 'begin' in '1074479104u', which is of pointer type 'Can*' (maybe you meant to use '->' ?)

I found the reason!
In the file sam3x8e.h, which is part of the due board definition files, there is already a definition of CAN0,


and the same name is also used in your example code. When I changed it to CAN00 in the example code, the sketch compiles!

1 Like

Hello

Mr klaric.gregor; I am newbie in can bus . i have seed studio can bus shield. and i use it with arduino mega.

I want to use with arduino due like you but i saw same error.

Please explain solution in details.

Thanks for advane.

In the example files they instantiate the can bus naming the connection CAN0
But this name is already used for something else in the Arduino DUE code.

So one has to replace all occurrences of CAN0 in the code with something else, for instance CAN or CAN00

So for example the line
CAN0.setMode(MCP_NORMAL);
becomes
CAN.setMode(MCP_NORMAL);

1 Like

One example still contains the old CS pin definition(10 instead of 9) and CAN0 instead of CAN.
Could you change that code to make them compatible with the current shield? Thank you!
The example in question:

1 Like

I tested the shield with the Arduino DUE today. It works great, and it is also much faster(much faster response time when the CAN Traffic is high) than the Arduino Mega.

1 Like