Hardware SPI Clock trouble

Hello all,

I am trying to work with Sharp's memory LCDs on my Arduino Zero and the LCD requires a 2MHz SPI clock. I am finding that if I set my SPI settings to use 2MHz I am only setting a clock of 150kHz with my oscilloscope. A setting of 1Mhz drops the clock down to about 91kHz... Am I doing something wrong or this a bug in the Arduino SPI library?

hi dlabun,

please can you post the code you use to set the spi?

Marco

Hi Marco,

I am using the following in my sketch to setup SPI:

SPI.begin();
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));

I am seeing data on the bus but it's very slow to the point the LCD doesn't even render properly.

As an idiot check I even tried the older SPI.setClockDivider(1); and I only saw a max clock of 300kHz. This was measured with an Agilent 34461A DMM with a loop continuously transmitting to the SPI bus so I'm pretty confident in the reading.

Thanks,
Doug

Hi dlabun,

as far as I know there is no such a function as SPI.beginTransaction in the Zero SPI library.

(I am using Arduino IDE 1.7.8 and an Arduino M0 PRO board).

If you want to set the SPI clock to 2MHz try the following code:

#include <SPI.h>

void setup() 

{
  SPI.begin();                                 // library default SPI clock is 4 MHz  
  
  
                                               // change the default setting
                                               //
                                               // use only even values
                                               // SPI clock frequency = 48MHz / value
                                                                                            
  SPI.setClockDivider(24);                     // value   SPI clock
                                               //   2      24 MHz      
                                               //   4      12 MHz 
                                               //   6       8 MHz 
                                               //   8       6 MHz 
                                               //  10     4.8 MHz  
                                               //  12       4 MHz
                                               //  14     3.4 MHz 
                                               //  16       3 MHz  
                                               //  18     2.6 MHz  
                                               //  20     2.4 MHz 
                                               //  22     2.1 MHz  
                                               //  24       2 MHz                                               
                                               //
                                               //  and so on ... 
                   
}

void loop() 

{
  SPI.transfer(0x55);                          // for ever loop 
}

Further take into account that measuring the SPI clock frequency with a frequency counter is not the right way to do it, since it is not continuous but bursty, even if you execute the SPI transfert in a tight loop.
To do this you definitly need an oscilloscope.

Marco

Hi Marco,

SPI.beginTransaction() is in the 1.6.2 version of the Zero libraries and 1.6.6. for the Due.

I do have an oscilloscope on the way so as soon as it arrives I'll run the SPI decoder on it to get a better idea of the clock speed.

Thanks,
Doug

Hi Doug,

I realized that we are using not only different versions of the IDE but that mine is from arduino.org and yours from arduino.cc

So we have different IDE and different libraries: the Arduino people really made a mess splitting in two :frowning:

Anyway I think that SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0)); is working correctly and that the problem is the way you use to measure the clock frequency.

Let me know what happen when you will have a scope available.

Ciao
Marco

Hi Marco,

The SPI bus looks correct when I am viewing it on my scope. The only strange thing I noted is the voltages are higher than I would have expected for a 3.3VDC part. I've attached a copy of the scope display (hopefully).

Thanks,
Doug

Hi,

you have some amount of undershoot and overshoot.

In electronics, overshoot refers to the transitory values of any parameter that exceeds its final (steady state) value during its transition from one value to another

Overshoot occurs when the transitory values exceed final value. When they are lower than the final value, the phenomenon is called "undershoot".

(from Wikipedia)

Provided that your probes are correctly calibrated, using the little screw present on them, in your case this is mostly due to the scope probes ground connections.

Don't worry this is completly normal and not a circuit or scope fail.

Marco