Hi,
I'm trying to change the SPI clock speed to accomodate for longer spi cables for my in-car project. I have the TFT+SD module, connected to an MEGA 2560. The display part works fine with long(4ft) calbe, meant to place the display on the dash of my electric car to display things while the mega sits under the seat in the battery tray doing the battery monitoring. The sd however did not like the long cable (initially did not respond untill i chopped it down to 10cm for fault finding).
I tried setting down the clock speed to help overcome the cable length, but the SPI.setClockDivider(SPI_CLOCK_DIV**)
command does nothing., neither does (SPI_HALF_SPEED, 4) I have an oscilloscope hooked up to the scl of the spi bus, and nothing changes with all the clock speeds from 2 to 128 tried.
I had to use the nightly build to get the display working in the first place, due to some obscure mismatch pointed out in a helpful post.
Below is my code, loading and displaying two alternating pictures from the sd card on the screen.
both the spi clocking option in top of setup have been tried. So has google, but after hours of searching, i am stuck.
Any ideas of what i am doing wrong?
#include <SPI.h>
#include <SD.h>
#include <TFT.h> // Arduino LCD library
// pin definition for the tft+sd module
#define sd_cs 4
#define lcd_cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(lcd_cs, dc, rst);
// this variable represents the image to be drawn on screen
PImage logo;
void setup() {
SPI.begin();
//(SPI_FULL_SPEED, 4); // Use digital 4 as the SD SS line
SPI.setClockDivider(SPI_CLOCK_DIV32);
pinMode(12, OUTPUT); //backlight level pin
analogWrite(12, 245); // set backlight level
TFTscreen.begin();
TFTscreen.background(55, 55, 55);
// clear the GLCD screen before starting
TFTscreen.background(55, 55, 55);
// try to access the SD card. If that fails (e.g.
// no card present), the setup process will stop.
if (!SD.begin(sd_cs)) {
return;
}
// initialize and clear the GLCD screen
TFTscreen.begin();
TFTscreen.background(255, 255, 255);
// now that the SD card can be access, try to load the
// image file.
}
void loop() {
logo = TFTscreen.loadImage("arduino.bmp");
if (!logo.isValid()) {
}
TFTscreen.image(logo, 0, 0);
delay(3000);
logo = TFTscreen.loadImage("1.bmp");
if (!logo.isValid()) {
}
TFTscreen.image(logo, 0, 0);
delay(3000);
}
The clock speed seems to be 4mhz on the spi bus by loking at the scope.