Arduino Uno/Nano SPI speed and System speed

Hi,

I've some questions about relationship between SPI speed and Arduino uni / nano speed.

My questions:

A: Regarding SPI

  1. What is the speed of SPI if I have Arduino Nano @16MHz ?
  2. If the speed; for example 15MHz, what should be the SPI speed ?
  3. In the datasheet; does Fosc mean the actual oscillator speed or the system speed ?
    Like in SPISettings class, what does the clock mean? The 16MHz or the system 2MHz?
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode)
  1. Also I found in a TFT library that uses SPI, this guard piece of code:
#if defined (ARDUINO_ARCH_ARC32)
  // max speed!
  SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
#else
  // max speed!
  SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
#endif

From my understanding of programming and one told me that ARDUINO_ARCH_ARC32 is related to intel chip; but how this if statement works ?! if the condition is true then SPI clock is 16MHz ! But how ?
I read Arduino 101 clock is 32MHz and not 16MHz.
The else of this if is 24MHz, what does this number mean ?

B: Regarding Arduino XTAL

  1. I've read in the datasheet this, p/51:

13.2.1 Default Clock Source
The device is shipped with internal RC oscillator at 8.0 MHz and with the fuse CKDIV8 programmed, resulting in 1.0 MHz system clock.

  1. Does this mean that the actual instruction execution speed in the case of XTAL 8MHz is 1 MIPS ?
  2. So in case of Arduino nano which runs @16MHz, is the system speed = 2 MIPS ?

Also read this, p/54:

If the crystal frequency exceeds the specification of the device (depends on VCC), the CKDIV8 fuse can be programmed in order to divide the internal frequency by 8.

It must be ensured that the resulting divided clock meets the frequency specification of the device.

My questions about this part:
4. I can run the atmega328p with a; for example, 40MHz oscillator ?
5. What does the last line mean ?

The max SPI speed you can get from an Atmega328P is half of the CPU speed. So for an Arduino running at 16MHz, max SPI is 8Mhz

You can only get 16MHz from an external clock/crystal as the internal oscillator is rated at 8MHz.

A new Atmega328P chip from the manufacturer runs at 1Mhz by default (8MHz osc divided by 8 because of the CKDIV8 fuse)

1 Like

Question B4:

The manufacturer specifies the maximum clock frequency at which they would guarantee correct operation of the device, and the associated operating voltage. In the case of the 328p, the max clock frequency is 16MHz @ 5V. (EDIT: it's actually 20MHz @ 5V) This frequency is reduced as the voltage is lowered. You can try running the 328p at a higher frequency but correct operation is not guaranteed.

Question B5:

There is a graph of frequency vs voltage in the datasheet. That will tell you the manufacturers recommended max frequency for the supply voltage you are using. My interpretation of that sentence is that the external clock frequency can be higher than the recommended frequency as long as you divide it down internally so that it is at or lower than the frequency from the graph.

1 Like

hzrnbgy:
The max SPI speed you can get from an Atmega328P is half of the CPU speed. So for an Arduino running at 16MHz, max SPI is 8Mhz

OK, that's a direct answer, thank you !

You can only get 16MHz from an external clock/crystal as the internal oscillator is rated at 8MHz.

Yes, Arduino boards are setup at this clock, but for the Atmega328p I can run it at 20MHz osccilator max, right ?

A new Atmega328P chip from the manufacturer runs at 1Mhz by default (8MHz osc divided by 8 because of the CKDIV8 fuse)

Is CKDIV8 a must in case when using the internal oscillator ? Also what about case when using the external oscillator ?
When CKDIV8 should/must be used or it's an optional fuse ?

The CKDIV is just the default. You can turn it off from software by changing some registers. But if you have a 20MHz crystal, you have to use it since 20MHz is outside the spec of the CPU.

The CKDIV applies whether you have an external crystal or using the internal oscillator

1 Like

markd833:
Question B4:

The manufacturer specifies the maximum clock frequency at which they would guarantee correct operation of the device, and the associated operating voltage. In the case of the 328p, the max clock frequency is 16MHz @ 5V. This frequency is reduced as the voltage is lowered. You can try running the 328p at a higher frequency but correct operation is not guaranteed.

I watched a video on YouTube overclocking an Arduino uno to 65MHz with Liquid Nitrogen and the Arduino still working.
But of course without liquid nitrogen 16MHz would be max.

Question B5:

There is a graph of frequency vs voltage in the datasheet. That will tell you the manufacturers recommended max frequency for the supply voltage you are using. My interpretation of that sentence is that the external clock frequency can be higher than the recommended frequency as long as you divide it down internally so that it is at or lower than the frequency from the graph.

I also got an understanding it's related to maintaining the internal clock.
So I guess for the 328p the internal max clock is 8MHz, more than that, device won't work. But with the OCing video I thin 328p can run to that max clock, means the internal clock could be more than 8MHz.

I made a mistake in one of my previous posts. The 328p can operate at up to 20MHz @ 5V.

At 5V, 16MHz seems to be the clock of choice. If you are down at 3.3V, then usually 8MHz is the frequency of choice. Probably because its half 16MHz and baud rates are still within tolerance.

The datasheet says 10MHz @ 2.7V with frequency increasing linearly to 20MHz @ 4.5V. So for 3.3V you could run a 13.333MHz clock and be within spec but serial baud rates may not divide out nicely enough to be within tolerance.

1 Like

markd833:
I made a mistake in one of my previous posts. The 328p can operate at up to 20MHz @ 5V.

At 5V, 16MHz seems to be the clock of choice. If you are down at 3.3V, then usually 8MHz is the frequency of choice. Probably because its half 16MHz and baud rates are still within tolerance.

The datasheet says 10MHz @ 2.7V with frequency increasing linearly to 20MHz @ 4.5V. So for 3.3V you could run a 13.333MHz clock and be within spec but serial baud rates may not divide out nicely enough to be within tolerance.

So the SPI always half the oscillator clock, right ?
What is SPI max speed in 328p ?
I read this in the datasheet regarding of system clock, ... etc.

If CKDIV8 is unprogrammed, the
CLKPS bits will be reset to ā€œ0000ā€. If CKDIV8 is programmed, CLKPS bits are reset to ā€œ0011ā€, giving a
division factor of 8 at start-up. This feature should be used if the selected clock source has a higher
frequency than the maximum frequency of the device at the present operating conditions. Note that any
value can be written to the CLKPS bits regardless of the CKDIV8 Fuse setting. The Application software
must ensure that a sufficient division factor is chosen if the selected clock source has a higher frequency
than the maximum frequency of the device at the present operating conditions. The device is shipped
with the CKDIV8 Fuse programmed.

It's obvious that the programmer must ensure that the device is within required operating conditions, and proper settings too. Otherwise, if device is clocked at higher speed, it won't work of course, it's like any other piece of electronics, if run over its manufacture specs, it could damage the device, it may not work or work abnormally.

So the SPI always half the oscillator clock, right ?

Max SPI speed is always half of the CPU clock. You can configure it to 1/4, 1/8, etc

1 Like

Default speed is 1/4 system clock.
So 4 MHz for a 16 MHz system.

If you want to run at 20 MHz, you need to unsolder the resonator and put a 20MHz part on.
You would then also want to install Minicore into the IDE so you can select the faster system clock and be able to download sketches.

CrossRoads:
Default speed is 1/4 system clock.
So 4 MHz for a 16 MHz system.

If you want to run at 20 MHz, you need to unsolder the resonator and put a 20MHz part on.
You would then also want to install Minicore into the IDE so you can select the faster system clock and be able to download sketches.

GitHub - MCUdude/MiniCore: Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB

Thanks for the answer. I'm not interested in doing 20MHz, I would rather use any faster board, ESP32 or maple mini.
My main concern was about SPI speed, and how it's setup inside the Arduino SPI library.
I want to know what does this mean, in ILI9488 library In found in GitHub in source file:

#if defined (ARDUINO_ARCH_ARC32)
  // max speed!
  SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
#else
    // max speed!
  SPI.beginTransaction(SPISettings(24000000, MSBFIRST, SPI_MODE0));
#endif

What I learned is that "ARDUINO_ARCH_ARC32" is for Arduino 101, but the id statement says that if it's the case of "ARDUINO_ARCH_ARC32" then the speed is 16000000 ! where the Arduino 101 is clocked at 32MHz. So what does this mean ?

Also the second part says, else the speed is 24000000. Which boards are out of the scope and has 24MHz ?

Which part in the library handle the normal Arduino boards that would run 4MHz SPI speed ?

This is the library for reference:

ILI9488.zip (7.75 KB)

I don't know about "ESP32 or maple mini. My main concern was about SPI speed, and how it's setup inside the Arduino SPI library."
I've not done any programming for those parts.

What peripherals are you planning to use that can take advantage of those much higher speeds?

1 Like

CrossRoads:
What peripherals are you planning to use that can take advantage of those much higher speeds?

Basically I'm interested in higher speeds, even if I wanted to, then I would use a faster board.
My questions are about the code structure of either the Arduino SPI library and ILI9488 library that use SPI but has speed conditions that I want to understand as in #10.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.