Hello all
I am trying to set up an SPI communication interface between the Arduino and a display. I am using the SPI library, but the SCK (which is the clock) does not seem to work for anything 1 MHz and above. I am pretty sure that the clock can generate signals up to 8 MHz. Does anyone know any trick around this that might require special set-up ?
The code am using is :
#include <SPI.h>
const int StartButton = 2;
void setup() {
Serial.begin(9600);
pinMode(StartButton,INPUT); //Start Pin Button As Output
pinMode(SS,OUTPUT);
pinMode(MOSI,OUTPUT);
pinMode(MISO,INPUT);
pinMode(SCK,OUTPUT);
SPI.begin();
}
void loop() {
int Start=LOW;
Start=digitalRead(StartButton);
digitalWrite(SS,HIGH);
SPI.beginTransaction(SPISettings(100000,MSBFIRST,SPI_MODE0)); // SPI Settings 1MHZ - Falling Edge - IDLE When Low
digitalWrite(SS,LOW);
SPI.transfer(0x1B);
SPI.endTransaction();
Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.
but the SCK (which is the clock) does not seem to work for anything 1 MHz and above.
How are you testing this?
Are you using an oscilloscope?
Yes I am using an oscilloscope. I also use the integrated LEDs. The L LED is connected to pin 13 which is the clock of the SPI bus, and it blinks for anything below 1MHz and is off for anything above
Thanks for making those changes to your first post.
I notice you code does not set the SPI clock divider:-
SPI - Arduino Reference
Remember you have a 16MHz clock only on the UNO.
The L LED is connected to pin 13 which is the clock of the SPI bus, and it blinks for anything below 1MHz and is off for anything above
On the Uno R3 the LED is driven through a LMV358 op amp. This has a unity gain bandwidth of 1MHz so you would not see any LED activity over 1MHz. Your scope is the only way to see it. I have used SPI clock rates of 4MHz in the past.
I can't tell what you're trying to do since you left out your code but by choosing 100kHz as the SPI clock you're actually setting it to 125kHz if you have a 16MHz board and half that if you have an 8MHz board.
Bedtime reading:
I use 8 MHz all the time to feed data into shift registers. Need to set spi clock divisor to 2.