Hello,
I can't figure out how to proper setup-up 3 devices together on SPI.
I'm using ARDUINO DUE R3, ARDUINO EHERNET SHIELD W5100 (with SD), DISPLAY TFT 2.8" 240X320 ILI9341.
I really wants to use sd module from Ethernet shield and ethernet together with display.
2 Separate modules works fine: Ethernet with SD | DISPLAY
I know that on SPI, CS pin should set HEIGHT on begin
But when i try tries to connect them ethernet it's not starting.
DEVICES list:
-DISPLAY TFT 2.8" 240X320 ILI9341 V1.2 https://www.amazon.com/Serial-Touch-Panel-Display-Module/dp/B0749QRJ3P
-ARDUINO EHERNET SHIELD W5100 (with SD) Amazon.com
LIBRARIES list:
-for Ethernet i'm using standard IDE library:
-for SD, I'm using SdFat library: SdFat/examples at master · greiman/SdFat · GitHub
-for TFT i'm using ILI9341_due
CS pinout:
CS SD 4
CS Ethernet 10
CS TFT 9
Code below:
#include <SPI.h>
//-----------------------SD card
#include <SdFat.h>
SdFat SD;
//-----------------------Ethernet
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169, 254, 106, 177);
EthernetServer server(80);
//-----------------------TFT screen
#include <ILI9341_due_config.h>
#include <ILI9341_due.h>
#include <SystemFont5x7.h>
#define TFT_RST 8
#define TFT_DC 7
#define TFT_CS 9
//-------------------------
void setup() {
Serial.begin(9600);
// disable Ethernet chip
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
// disable TFT display
pinMode(TFT_CS, OUTPUT);
digitalWrite(TFT_CS, HIGH);
tft.begin();
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
//Some display functions
for(uint8_t rotation=0; rotation<4; rotation++) {
tft.setRotation((iliRotation)rotation);
testText();
delay(1000);
}
}
EFFECT console:
Initializing SD card...
ERROR - SD card initialization failed!
TFT Display is working proper
Please could anyone help me?
This tutorial might help you out:
Quick, how do you wire up an SPI bus between a microcontroller and a peripheral? SCK goes to SCK, MISO goes to MISO, and MOSI goes to MOSI, right? Yeah. You’ll need to throw in a chip select …
Note that USART0 and USART1 can be used as SPI masters too.
Sorry for bothering.
I found myself how to solve quiz.
I add chip select to the SD begin.
Working code below if someone find useful:
#include <SPI.h>
//-----------------------SD card
#include <SdFat.h>
SdFat SD;
#define SD_SPI_SPEED SPI_HALF_SPEED // SD card SPI speed, try SPI_FULL_SPEED
//-----------------------Ethernet
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169, 254, 106, 177);
EthernetServer server(80);
//-----------------------TFT screen
#include <ILI9341_due_config.h>
#include <ILI9341_due.h>
#include <SystemFont5x7.h>
#define TFT_RST 8
#define TFT_DC 7
#define TFT_CS 9
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
ILI9341_due tft = ILI9341_due(TFT_CS, TFT_DC, TFT_RST);
//-------------------------
void setup() {
Serial.begin(9600);
// disable Ethernet chip
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
// disable TFT display
pinMode(TFT_CS, OUTPUT);
digitalWrite(TFT_CS, HIGH);
tft.begin();
// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4, SPI_HALF_SPEED)) { // <-------------------------------- changed line
Serial.println("ERROR - SD card initialization failed!");
return; // init failed
}
Serial.println("SUCCESS - SD card initialized.");
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
//Some display functions
for(uint8_t rotation=0; rotation<4; rotation++) {
tft.setRotation((iliRotation)rotation);
testText();
delay(1000);
}
}
unsigned long testText() {
tft.fillScreen(ILI9341_BLACK);
unsigned long start = micros();
tft.cursorTo(0, 0);
tft.setFont(SystemFont5x7);
tft.setTextColor(ILI9341_WHITE); tft.setTextScale(1);
tft.println("Hello World!");
tft.setTextColor(ILI9341_YELLOW); tft.setTextScale(2);
tft.println(1234.56);
tft.setTextColor(ILI9341_RED); tft.setTextScale(3);
tft.println(0xDEADBEEF, HEX);
tft.println();
tft.setTextColor(ILI9341_GREEN);
tft.setTextScale(5);
tft.println("Groop");
tft.setTextScale(2);
tft.println("I implore thee,");
tft.setTextScale(1);
tft.println("my foonting turlingdromes.");
tft.println("And hooptiously drangle me");
tft.println("with crinkly bindlewurdles,");
tft.println("Or I will rend thee");
tft.println("in the gobberwarts");
tft.println("with my blurglecruncheon,");
tft.println("see if I don't!");
return micros() - start;
}