Go Down

Topic: Changing clock frequency in DUE (Read 3608 times) previous topic - next topic


Nov 07, 2017, 11:54 am Last Edit: Nov 08, 2017, 09:13 am by chutki
Hello al,

I would like to establish an UART communication between DUE and sensor. The sensor I have works at 16mhz and the baud rate is 38400. DUE works at 4mhz , default . I would like to change the DUE to 16mhz. When I looked into datasheet of SAM, there are many clock sources and one of the clock sources is the crstal of 3-20mhz. This can be selected as main clock using the MOSCSEL bit in the Main Oscillator Register (CKGR_MOR) . But thr pre-scaler values cannot make them to 16mhz .Am I right?

Question 2:
How can I access the low level registers ? Just like they have accesed for PWM from this link : https://forum.arduino.cc/index.php?topic=386981.0

Is it possible to write code for arduino due via Atmel Studio 7 ? I want to change the clock frequency of the Arduino DUE and I found no way on the Arduino IDE. IS this possible through Atmel,Studio ?


DUE works at 4mhz , default
Due runs at 84MHz by default, so I'm not sure what you're talking about...
(And the Due Serial ports should work fine at 38400 using "SerialX.begin(38400)", with no changes to clocking or low-level USART hacking.
The clock is initialized in .../packages/arduino/tools/CMSIS-Atmel/1.1.0/CMSIS/Device/ATMEL/sam3xa/source/system_sam3xa.c

How can I access the low level registers ?
The proper definitions are already included; you access them via the CMSIS definitions or by the REG_ definitions.


Due runs at 84MHz by default, so I'm not sure what you're talking about...
(And the Due Serial ports should work fine at 38400 using "SerialX.begin(38400)", with no changes to clocking or low-level USART hacking.
So ,DUE works at 84mhz and the other device is at 16mhz . And still the UART is possible with same baud rate in UART . Right?



Questions regarding this:

1.) Is it possible to change the clock frequency in the IDE itself and if so, how?

2.)What exactly do you need to change in the system_sam3x.c file to change the clock frequency to say 16 MHz? I'll attach what I see on the file.


Jan 26, 2020, 06:35 pm Last Edit: Jan 26, 2020, 06:36 pm by ard_newbie
It's possible to change the master clock frequency (in a certain extent though), the posted code plus the datasheet is all you need. The default frequency of a DUE is 84 MHz with 3+1 wait states.

What Master clock frequency are you willing to have on your board instead of 84 MHz ?


Jan 27, 2020, 11:02 am Last Edit: Jan 27, 2020, 11:04 am by Aero2019
Thank you for your response. I am trying to use multiple sensors with the Arduino DUE but it appears some libraries are not written to work well with higher than average clock speeds like the DUE provides. I am hoping to change the Master clock speed to 16 MHz while taking advantage of the other features that the DUE offers. Looking at the at the data sheet here:


I am still not sure where the instructions are for changing clock speed. Looking up a few posts it seems like people are trying different things that I don't understand including this:

Code: [Select]

void setup() {
    while (!pmc_osc_is_ready_32kxtal());

I am really hoping to just change the speed to around 16 MHz.. any specific ideas?

Thank you in advance.


The master clock of the Due is not going to be the clock speed your sensor will be using, the Due will downscale the communication speed to whatever you set the appropriate registers to for whatever sensors you are using.
Can you tell us what sensors you are using?


Oh, I didn't realize registers were a thing to do this.. do you happen to have any reference so I can further read on it? The stuff I look up seems unrelated.. What I use involves load cells but my thesis involves the following:

9 DOF IMU                   Adafruit 9-DOF Absolute Orientation IMU Fusion Breakout - BNO055
Luminosity Sensor           Adafruit TSL2591 High Dynamic Range Digital Light Sensor [ADA1980]
Spectroscopy Sensor           SparkFun Triad Spectroscopy Sensor - AS7265x
Infrared Camera Sensor    FLIR Radiometric Lepton Dev Kit V2
Thermistors                   DIKAVS 3950 NTC 10K Precision Epoxy Thermistor Temperature Sensor
Main Camera Preference   OV5642 - 5.0 MP Mini Module Camera Shield
Backup Camera                   TTL Serial JPEG Camera with NTSC Video

One of my concerns is that any of these will be affected by clock speeds so I really need to understand all this stuff before I get there as payloads aren't my only concern.. I plan to end up using the Arduino Portenta H7 and as an aerospace person I don't have much experience with in-depth EE stuff..


The wire library looks reasonable for the I2C bus devices, you can set the clock using the SetClock() function:

SPI is similar:
You can have all sorts of SPI clock speeds, pretty much any integer subdivision of 84MHz. I don't recommend 42MHz unless you have a good layout or coax cable for the clock!
16MHz isn't possible unfortunately, the nearest is 14MHz, or you could try 16.8MHz (most devices will overclock a little on the SPI bus)

Your project looks really interesting! Can you tell us what it is?


Thanks so much for the info! Sorry it took me so long to reply. But yes my project is a project for the Cal Poly CubeSat Laboratory (Polysat.org). As a member of the aerospace team and as  a grad student, I'm working on an agile CubeSat kit that is open source which will act as an education tool for us to teach domestic and international communities about the technology in our CubeSats, but in an open source way. It will also work as a backup satellite for any mission as it enables quick development. I need to do all the formal space-based environmental testing on the electronics and such to assess performance in space as well. Many things go into it!


Feb 06, 2020, 05:22 am Last Edit: Feb 06, 2020, 06:19 am by ard_newbie
At least a super COoooooOl project !

Go Up