I’ve started writing a new library that let to use the integrated peripherals into the Atmel SAM3X8E microcontroller of the Arduino DUE board that are not yet supported by the Arduino IDE core.
At the moment the library, called advancedFunctions, supports the real time clock (RTC), that provides the timing and a calendar, and an alarm too, and the true random number generator (TRNG) that has passed the NIST tests too. The support for other hardware will be added in the future.
To use the library, download the package that you find at the end of this article and uncompress it. When you have extracted the folder advancedFunctions, move it into the folder /libraries that the very latest versions of the Arduino IDE 1.5.x create into the sketches’ folder, that it’s now named /Arduino. To know where the sketches’ folder is located, open the IDE and click on the menu at “File/Preferences”. After you did this, you’re ready to use the functionalities of the library by simply adding it to your sketch with the following instruction:
#include "advancedFunctions.h"
As I said before, the library doesn’t support all the hardware integrated into the microcontroller that is not supported by the Arduino core. Being it at a very early stage, at the moment it only supports the following peripherals (more functionalities will be added later):
RTC (Real Time Clock) module
The RTC integrated into the SAM3X8E is a real time clock capable of timing, calendar and alarm for month/day/hours/minutes/seconds (still to be supported) functionalities. These functionalities are available with the object rtc. You can find the instructions on how to use it into the file RTC_MODULE.txt.
Important! The user Embed has pointed my attention on the fact that by default the chip SAM3X8E doesn’t use the external 32 kHz crystal but instead makes use of an internal RC oscillator, not so precise. So I introduced a fix into the file myRtc.cpp that enables the use of the external crystal. In case your Arduino DUE wouldn’t have this crystal (some boards of the very first production lot didn’t have it) or if you are using a standalone chip without that crystal, the RTC module won’t run because it won’t have a valid clock source. You simply have to modify the above file following the directions that I’ve written into the doc file named RTC_MODULE.txt.
TRNG (True Random Number Generator) module
The TRNG that is integrated into the microcontroller is very robust and it has passed the America NIST Special Publication 800-22 and Diehard Random Tests Suites. It is capable to generate 32 bits of entropy with very high casuality (so the name of “true” generator) every 84 clock cycles. You can find the instructions on how to use it into the file TRNG_MODULE.txt.
WDT (WatchDog Timer)
The WatchDog Timer is a timer that can reset the microcontroller if the code becomes trapped in a deadlock. The user can choose the interval in milliseconds between 1 and 16000.
IMPORTANT: to use this module you have to edit a file of the Arduino core (read the /doc/WDT_MODULE.txt).
License and warranties
The library and the included examples are released under the terms of the GNU General Public License 3.0. The software is provided as is, without any warranty for its functioning and without any liability for its usage. More details are included into the file README_FIRST.txt and in the doc files inside the /doc folder.
Today I tried the test_RTCmodule example; I only modified it to use SerialUSB instead of Serial for the console output.
The output is formally as expected, however the seconds count slower than real seconds (about 10 per minute). I checked the 32768Hz clock with an oscilloscope directly at the quartz pins on my Due (and another one…) and noticed there are no clock ticks (I had noticed this behavior before using RTC).
My Arduino IDE is 1.5.4 (current version). I guess the external slow clock must be activated somehow, otherwise a non-accurate internal clock will be used, leading to the observed deviation. Note that the deviation may be less on other boards due to the manufacturing tolerances.
I expect that the Watchdog accuracy is affected as will, but have not yet checked.
I found a solution for the non-active external slow clock in the Arduino Due forum:
http://forum.arduino.cc/index.php?PHPSESSID=bm8qphphg49i3ris1o1dkfc041&topic=187128.0
The suggestion of the author should be taken, it makes no sense to include an accurate RTC quartz on the Due but then not activate it.
Meanwhile, until this issue is fixed (hopefully), you should include the patch in your documentation.
I’ve fixed it. I also discovered 2 things:
1) the fix suggested in that thread doesn’t work;
2) a little quantity of DUE from the very first production lot doesn’t have that crystal!