<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openinverter.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NiklasBuilds</id>
	<title>openinverter.org wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://openinverter.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NiklasBuilds"/>
	<link rel="alternate" type="text/html" href="https://openinverter.org/wiki/Special:Contributions/NiklasBuilds"/>
	<updated>2026-04-29T08:03:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://openinverter.org/wiki/index.php?title=CAN_bus_with_Arduino_Due&amp;diff=2364</id>
		<title>CAN bus with Arduino Due</title>
		<link rel="alternate" type="text/html" href="https://openinverter.org/wiki/index.php?title=CAN_bus_with_Arduino_Due&amp;diff=2364"/>
		<updated>2022-04-01T13:57:12Z</updated>

		<summary type="html">&lt;p&gt;NiklasBuilds: /* Configure your Arduino IDE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;You can analyse CAN bus traffic using an Arduino Due. &lt;br /&gt;
&lt;br /&gt;
You will need the following:&lt;br /&gt;
* An Arduino Due board&lt;br /&gt;
* Two SN65HVD230-based CAN transceivers&lt;br /&gt;
* An SPI Micro SD storage module (optional)&lt;br /&gt;
Here are the steps:&lt;br /&gt;
&lt;br /&gt;
== Configure your Arduino IDE ==&lt;br /&gt;
Download and install the [https://www.arduino.cc/en/Main/Software Arduino IDE] on your computer&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tools -&amp;gt; Board -&amp;gt; Boards Manager&#039;&#039;. Type &amp;quot;due&amp;quot; in the search box and install &amp;quot;Arduino SAM Boards (32-bits ARM Cortex-M3)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Connect your computer to the &amp;quot;native&amp;quot; USB port on the Arduino Due board with a USB cable. The Due has two USB ports and they&#039;re used for different purposes. The port closer to the DC power connector is the &amp;quot;programming port&amp;quot; and the second is the &amp;quot;Native USB Port&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Make sure your Arduino board is selected with &#039;&#039;Tools -&amp;gt; Board: &amp;quot;Arduino Due (Native USB port)&amp;quot;.&#039;&#039; Choose also the right port for the DUE from &#039;&#039;Tools -&amp;gt; Port.&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;File -&amp;gt; Examples -&amp;gt; 01.Basics -&amp;gt; Blink&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sketch -&amp;gt; Upload&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Push the reset button on your Due. You should now see a blinking light. Congratulations! You&#039;ve successfully compiled and loaded your first program and your IDE is working.&lt;br /&gt;
== Get CAN transceivers working ==&lt;br /&gt;
The Due has two on-board CAN interfaces. However, the board lacks the necessary CAN transceivers to make then useful. You will need to add the transceivers yourself. You can find suitable 3.3V SN65HVD230-based CAN transceivers easily on eBay. They are very cheap. Unfortunately, not all of them work.&lt;br /&gt;
[[File:SN65HVD230 CAN bus transceiver faulty.jpg|thumb|This SN65HVD230 transceiver did not work]]&lt;br /&gt;
Initially, I tried tiny ones that look like this. They were all faulty.&lt;br /&gt;
[[File:SN65HVD230 CAN bus transceiver working.jpg|thumb|This SN65HVD230 transceiver worked]]&lt;br /&gt;
I tried some bigger ones with screw terminals. These all worked perfectly.&lt;br /&gt;
&lt;br /&gt;
Connect your transceivers to the Due board&lt;br /&gt;
&lt;br /&gt;
The CAN0 interface is on the pins marked CANRX and CANTX&lt;br /&gt;
&lt;br /&gt;
The CAN1 interface is on the pins marked DAC0 (RX) and 53 (TX)&lt;br /&gt;
[[File:Due CAN loopback test.jpg|alt=Due CAN loopback test|thumb|Due CAN loopback test]]&lt;br /&gt;
Connect the CAN bus on the two transceivers together (CANL to CANL, CANH to CANH)&lt;br /&gt;
&lt;br /&gt;
Connect your computer to the the &amp;quot;native&amp;quot; USB port on the Arduino Due board with a USB cable and make sure &#039;&#039;Tools -&amp;gt; Board: &amp;quot;Arduino Due (Native USB port)&amp;quot;&#039;&#039; is selected. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tools -&amp;gt; Manage Libraries...&#039;&#039; Type &amp;quot;due_can&amp;quot; in the search box and install &amp;quot;due_can&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;File -&amp;gt; Examples -&amp;gt; due_can -&amp;gt; CAN_ExtendedPingPong&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sketch -&amp;gt; Upload&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tools -&amp;gt; Serial Monitor&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If your CAN transceivers are working properly, you should be rewarded with incrementing numbers in  the serial monitor window.&lt;br /&gt;
&lt;br /&gt;
== Install GV-RET ==&lt;br /&gt;
Once you&#039;ve confirmed that your CAN transceivers are working, you can move on to installing the [https://github.com/collin80/GVRET Generalized Electric Vehicle Reverse Engineering Tool (GV-RET)]. This software will allow your Due CAN transceivers to talk to SavvyCAN.&lt;br /&gt;
&lt;br /&gt;
You need to install a number of libraries (in addition to the due_can library installed in the last section). These are all linked to on the GV-RET website, but a couple of them may not work properly if you install them via that method. I recommend you install the following via the Arduino IDE Library Manager with &#039;&#039;Tools -&amp;gt; Manage Libraries...&#039;&#039; :  &lt;br /&gt;
* SdFat&lt;br /&gt;
* DueFlashStorage&lt;br /&gt;
Now install the remaining libraries manually. In each case, the installation procedure is:&lt;br /&gt;
# Download the .zip file&lt;br /&gt;
# Rename the file to remove &amp;quot;-master&amp;quot; or any other postfixes. This is important!&lt;br /&gt;
# Install the library with &#039;&#039;Sketch -&amp;gt; Include Library -&amp;gt; Add .ZIP Library...&#039;&#039; and select the file. Check that the names of the ZIP-files and the main folders in the ZIP-files are exactly as the packages listed below.&lt;br /&gt;
You need all of these:&lt;br /&gt;
* [https://github.com/collin80/due_can due_can]&lt;br /&gt;
* [https://github.com/collin80/can_common can_common]&lt;br /&gt;
* [https://github.com/macchina/mcp2515 MCP2515]&lt;br /&gt;
* [https://github.com/collin80/due_wire due_wire]&lt;br /&gt;
* [https://github.com/collin80/Wire_EEPROM Wire_EEPROM]&lt;br /&gt;
Once the libraries are all installed, you can install GV-RET. Go to the [https://github.com/collin80/GVRET GitHub webpage], and click on Code -&amp;gt; Download .ZIP.&lt;br /&gt;
&lt;br /&gt;
Expand the .zip file and put the folder in your Arduino sketchbook location. Open the GV-RET project and install it as follows:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;File -&amp;gt; Open -&amp;gt; GVRET.ino&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Sketch -&amp;gt; Upload&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Tools -&amp;gt; Serial Monitor&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If it doesn&#039;t compile and complains about missing libraries or headers, check the folder names in the Library folder. Remove any &amp;quot;-master&amp;quot; suffixes from the folder names. The folder names should match the library names listed above. If you installed wrong libraries (with a wrong name etc), delete them fist by deleting their folders from the arduino folder. For example with Windows users the folder can be C:\Users\Username\Documents\Arduino\libraries&lt;br /&gt;
&lt;br /&gt;
If everything worked, you should be rewarded with the following messages in the serial console:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Resetting to factory defaults&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Using stored values for digital toggling system&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Running on CANDue hardware&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;11977 - ERROR: Could not initialize SDCard! No file logging will be possible!&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Build number: 343&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Done with init&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congratulations! Your Due is now a powerful CAN sniffer and injection tool. You can connect the CAN-H and CAN-L terminals of a CAN bus transceiver to the CAN bus in your vehicle. &lt;br /&gt;
&lt;br /&gt;
== Add logging to SD card (optional) ==&lt;br /&gt;
You may have noticed the error message about the SD card. If you have an SPI SD card storage module, your Due will log CAN traffic to this for later analysis. This is ideal if you don&#039;t want to have to drive around with a laptop on the passenger seat...&lt;br /&gt;
&lt;br /&gt;
The SD card module needs to be connected to the SPI header (in the middle of the Due board), plus one additional wire to data line 10.&lt;br /&gt;
[[File:Due SPI pins.png|alt=Due SPI pins|thumb|Due SPI pins]]&lt;br /&gt;
Here are the connections:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+SD module wiring&lt;br /&gt;
!Pin on Due&lt;br /&gt;
!Pin on SD module&lt;br /&gt;
|-&lt;br /&gt;
|SPI MISO&lt;br /&gt;
|MISO&lt;br /&gt;
|-&lt;br /&gt;
|SPI SCK&lt;br /&gt;
|SCK&lt;br /&gt;
|-&lt;br /&gt;
|SPI VCC&lt;br /&gt;
|VCC&lt;br /&gt;
|-&lt;br /&gt;
|SPI MOSI&lt;br /&gt;
|MOSI&lt;br /&gt;
|-&lt;br /&gt;
|SPI GND&lt;br /&gt;
|GND&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
|CS&lt;br /&gt;
|}&lt;br /&gt;
The SD module can be a bit finicky. The GV-RET software defaults to running the SPI bus at 50MHz, but this didn&#039;t work for me. So you will need to do a bit of tweaking to fix this.&lt;br /&gt;
&lt;br /&gt;
First of all, check your SD card is working with File -&amp;gt; Examples -&amp;gt; SdFat -&amp;gt; QuickStart. Connect your Due to the &#039;&#039;&#039;Programming USB Port&#039;&#039;&#039; (not the Native USB Port) and upload the program. In the serial console, it will ask for the CS pin. Enter &#039;10&#039;. You should see a little report in the serial console that shows it is working.&lt;br /&gt;
&lt;br /&gt;
It may say you need to reformat your SD card. To do this, go to File -&amp;gt; Examples -&amp;gt; SdFat -&amp;gt; SdFormatter. Edit the source code to set the CS pin to 10 and limit SD clock speed to 4MHz:&lt;br /&gt;
 const uint8_t chipSelect = 10;&lt;br /&gt;
&lt;br /&gt;
 #define SPI_SPEED SD_SCK_MHZ(4)&lt;br /&gt;
Upload the program and follow the instructions to format your SD card.&lt;br /&gt;
&lt;br /&gt;
Now go to your GVRET code. Add this line after the line &#039;SdFat sd;&#039; :&lt;br /&gt;
 #define SPI_SPEED SD_SCK_MHZ(4)&lt;br /&gt;
Find the line &#039;if (!sd.begin(SysSettings.SDCardSelPin, SPI_FULL_SPEED)) {&#039; and change it to:&lt;br /&gt;
 if (!sd.begin(SysSettings.SDCardSelPin, SPI_SPEED)) {&lt;br /&gt;
[[File:Due CAN bus logger with SD card storage.jpg|alt=Due CAN bus logger with SD card storage|thumb|Due CAN bus logger with SD card storage]]&lt;br /&gt;
That should be enough to get it working. Upload the sketch (this time using the &#039;&#039;&#039;Native USB Port&#039;&#039;&#039;) and you should be rewarded with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Resetting to factory defaults&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Using stored values for digital toggling system&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Running on CANDue hardware&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Build number: 343&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Done with init&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At least the error message is gone. So far I haven&#039;t managed to get it to log anything to the SD card. It may be the GV-RET configuration needs to be tweaked...&lt;br /&gt;
&lt;br /&gt;
== Get started with SavvyCAN ==&lt;br /&gt;
&lt;br /&gt;
SavvyCAN is a free, open source tool for analysing CAN traffic. Download and install it on your computer.&lt;br /&gt;
It can be a bit intimidating, so here&#039;s a 30 minute tutorial to help you find your feet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;youtube&amp;gt;kdA5Gdf3FAk&amp;lt;/youtube&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you&#039;re too impatient to sit through a tutorial, just dive straight in and connect to your Due. Go back to the Arduino IDE and note down the name of your Due&#039;s USB connection. On my Mac, it&#039;s &amp;quot;/dev/cu.usbmodem2441&amp;quot;. You&#039;re now finished with the Arduino IDE, so quit it just in case it interferes with the next step...&lt;br /&gt;
&lt;br /&gt;
In SavvyCAN:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Connection -&amp;gt; Open Connection Window&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Add New Device Connection&#039;&#039; and select the USB connection you noted earlier&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Create New Connection&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check &amp;quot;Enable Bus&amp;quot; and set the Speed to match your CAN bus. 500000 is a good guess. You can always change it later.&lt;br /&gt;
&lt;br /&gt;
After a few seconds, you should see &amp;quot;Connected&amp;quot; in the Status field. If it doesn&#039;t connect, try pushing the reset button on your Due or click &amp;quot;Reset Selected Device&amp;quot; in SavvyCAN. &lt;br /&gt;
&lt;br /&gt;
Now on to the fun part...&lt;br /&gt;
== Start hacking ==&lt;br /&gt;
Feel free to add SavvyCAN examples here.&lt;br /&gt;
&lt;br /&gt;
I will add something on my Ampera BMS (once I figure out an easy way to connect to the CAN bus...)&lt;/div&gt;</summary>
		<author><name>NiklasBuilds</name></author>
	</entry>
</feed>