Arduino DUE SPI MOSI Problems

Hi,
i have a problem with my DUE. My Hardware are the Ethernet Shield 2: Link and the ITDB02-5.0 DisplayLink.

Both are using the SPI Bus, the CS-Pin for the Display is 7 and for the shiel is 10.

The most of my sketch works, including the SPI communication to the Ethernet Shield 2.
But the thing that isn’t working, is loading pictures from the SD Card Socket on the Display.
It does only load thw Pictures when i remove MISO from the Ethernet shield.
Does anybody have an idea why it isn’t working?

// 1.Einbinden der Bibliotek
#include <UTFT.h>  //Bildschirm
#include<URTouch.h> //Touchscreen
#include <SPI.h>  //SPI Kommunikation zum EthernetBoard
#include "SdFat.h" //Speicherkarte zusatz
#include <UTFT_SdRaw.h>  //Speicherkarte
#include <Wire.h> //I2C
#include <Ethernet2.h> //EThernet
#include <EthernetUdp2.h>    //UDP für Shield 2

//2.Laden der Schriftarten
extern uint8_t SmallFont[]; // Größe in x und y = 8x12
extern uint8_t BigFont[]; //Größe in x und y = 16x16
extern uint8_t GroteskBold24x48[]; //Muss sich im Ordner befinden Größe in x und y = 24x48

//Anzeige I/Os Konfigurieren
UTFT myGLCD(ITDB50,43,45,47,49);
URTouch myTouch( 38, 40, 42, 46, 48); 

//SD-Karte konfigurieren
UTFT_SdRaw myFiles(&myGLCD);
#define SD_CHIP_SELECT  7 // SD Auswahlpin Chipselect
SdFat sd;

//Temperatursensor Adresse und Prozessorchip setzen
#define Addr 0x27
#define AT91SAM3X8E

//Variablen deklarieren
boolean Schleife_2 = true;  //Schleife
byte stunden_1 =0; 
byte minuten_1 =0;
byte sekunden_1 =0;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char Feucht[9];
char Warm[9];
char lol []={"00:00:00"};
char liste[60] ={ 0x00, 0x01, 0x02, 0x03, 0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59};
//char Zeiten [90]={0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,10,11,12,13,14,15,16,17,18,19,0,0,0,0,0,0,20,21,22,23,24,25,26,27,28,29,0,0,0,0,0,0,30,31,32,33,34,35,36,37,38,39,0,0,0,0,0,0,40,41,42,43,44,45,46,47,48,49,0,0,0,0,0,0,50,51,52,53,54,55,56,57,58,59};
float a=0;
float b=0;
float wert=0;
float feuchte =0;
float cTemp =0;
int s=0;
int i=0;
int x,y;
int Paket; //Variable for the incoming string
int Stunden=0;
int Minuten=0;
int Sekunden=0;
int nummern_1 = 0;
int nummern_2 = 0;
int nummern_3 = 0;
int nummern_4 = 0;
int nummern_5 = 0;
int nummern_6 = 0;
int nummern_7 = 0;
int nummern_8 = 0;
int sichern_1 = 0;
int sichern_2 = 0;
int sichern_3 = 0;
int sichern_4 = 0;
int sichern_5 = 0;
int sichern_6 = 0;
int sichern_7 = 0;
int sichern_8 = 0;
String nulll = String("0");
String stringh;
String stringmin;
String stringsek;
String doppel = String(":");
String stringges;
unsigned long lastReadingTime = 0;
unsigned long lastmillis = 0;

 //Einstellung MAC adresse //Settings MAC addresse  
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x22, 0xEE};

// IP Einsellungen //Ip settings
IPAddress ip(nummern_1, nummern_2, nummern_3, nummern_4);
IPAddress gateway(nummern_5, nummern_6, nummern_7, nummern_8);

EthernetUDP Udp;
#define UDP_CHIP_SELECT  10


void loop() {
 if(s==0)
  { 
  Paket = Udp.parsePacket(); //Empfange packet //receive the Packet
 if(Paket) {
   Serial.print("Received packet of size ");
    Serial.println(Paket);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i = 0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
Serial.print(", port ");

    Serial.println(Udp.remotePort());
   Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);
    delay(1000);
  Udp.beginPacket(Udp.remoteIP(), 8888);
    Udp.write(Feucht);
    Udp.endPacket();
    Serial.println("Feuchte in %");
Serial.println(Feucht);
delay(3); 
  Udp.beginPacket(Udp.remoteIP(), 8888);
    Udp.write(Warm);
    Udp.endPacket();
    delay(3); 
  Udp.beginPacket(Udp.remoteIP(), 8888);
    Udp.print(stringges);
    Udp.endPacket();
    Serial.println("Wärm in C");
Serial.println(Warm);
Serial.println("Orginal Werte:");
 Serial.println("Feuchte in %");
Serial.println(feuchte);
Serial.println("Wärm in C");
Serial.println(cTemp);
Serial.println("Uhrzeit:");
Serial.println(stringges);
  for(int c=0;c<UDP_TX_PACKET_MAX_SIZE;c++) 
  { packetBuffer[c] = 0;  }
}
        if (millis() - lastReadingTime > 860) 
        {
   Uhr(); //lade Uhrzeit
  analog(); //lade Luftdruck
     tmp_lesen (); //lade Feuchtigkeit und Temperatur
      lastReadingTime = millis();   
    }
  }
if(s==1) //Beende Loop2
  {
   s=0; //gehe ins Normal Programm
    screen1(); //lade Bildschirm1
     attachInterrupt(8, screen2, FALLING); //erlaube den Bildscirminterrupt
   }
   
if(s==2)
{loop2();} // Fuehre das Einstellungfenster Aus

if(s==3)
{Uhrstellen();} // Fuehre Programm Uhrzeitstellen aus

if(s==4)
{IPstellen();} // Fuehre Programm IPstellen aus

if(s==5)
{Router();} // Fuehre Programm Routerstellen aus

if(s>5||s<0)
{s=1;} //verhindere das s im undefinierten bereich ist
}

You apparently left out part of your sketch. Where is your setup function?

Sorry forgoten

void setup() 
{
  nummern_1 = 172; //nummern_1 - nummern_4 stellen der IP
  nummern_2 =17;
  nummern_3 = 17;
  nummern_4 =210;
  nummern_5 = 172; //nummern_5 - nummern_8 stellen des Routers
  nummern_6 =17;
  nummern_7 = 17;
  nummern_8 =1;
  pinMode(UDP_CHIP_SELECT, OUTPUT);
  pinMode(SD_CHIP_SELECT, OUTPUT);
  digitalWrite(SD_CHIP_SELECT,LOW);
  digitalWrite(UDP_CHIP_SELECT,HIGH);
  IPAddress ip(nummern_1, nummern_2, nummern_3, nummern_4);
IPAddress gateway(nummern_5, nummern_6, nummern_7, nummern_8);
  myTouch.InitTouch(); //Starten des Touchscreens
!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED);  // Starten der SD
 SPI.begin();
 digitalWrite(SD_CHIP_SELECT,HIGH);
  digitalWrite(UDP_CHIP_SELECT,LOW);
    Wire.begin(); //Starte I2C
    myTouch.setPrecision(PREC_EXTREME); //setze Präzision auf max
      myGLCD.InitLCD(LANDSCAPE); //Bildschirmmodus Querformat
        myFiles.load(0, 0, 800, 480, "ETH_logo_mHg2.RAW", 1 );  //Datei laden
         delay(3000); //Warten das mHg2 schoen angezeigt wird
           screen1(); //lade Bildschirm1
            analogReadResolution(12);   //Einstellen auf Analogread von 2 hoch 12 also 4096 Werten      
attachInterrupt(8, screen2, FALLING); //Bildschirm interrupt aktivieren
Ethernet.begin(mac, ip); //Starte der IP-Einstellungen 
Udp.begin(8888); //Öffne den Port
Serial.begin(9600); //Starte uebertragung an den Seriellen Monitor
Udp.begin(8888); //Öffne den Port
  Serial.print("server is at ");
   Serial.println(Ethernet.localIP());
}

Do not set D4 or D10 as OUTPUT! Set them HIGH only. It is a Due challenge with those pins.

// don't do this!
  pinMode(UDP_CHIP_SELECT, OUTPUT);
  pinMode(SD_CHIP_SELECT, OUTPUT);

Okay i Changed it but still not working

#define SD_CHIP_SELECT  4 // SD Auswahlpin Chipselect



In the Setup:

// pinMode(UDP_CHIP_SELECT, OUTPUT);
 // pinMode(SD_CHIP_SELECT, OUTPUT);
  digitalWrite(SD_CHIP_SELECT,LOW);
  digitalWrite(UDP_CHIP_SELECT,HIGH);
  IPAddress ip(nummern_1, nummern_2, nummern_3, nummern_4);
IPAddress gateway(nummern_5, nummern_6, nummern_7, nummern_8);
  myTouch.InitTouch(); //Starten des Touchscreens
!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED);  // Starten der SD
 SPI.begin();

Compile and upload this test code. Does it show 192.168.0.2 on the serial monitor?

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  digitalWrite(4,HIGH);
  // disable the display
  digitalWrite(7, HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}

Yes it shows me, but i found some things

#include <SPI.h>
#include <Ethernet.h> --> #include <Ethernet2.h> i'm using the ethernet shield 2 so there is a own Library

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; --> 0x90, 0xA2, 0xDA, 0x10, 0x22, 0xEE static adress
IPAddress ip(192,168,0,2);

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  digitalWrite(4,HIGH);
  // disable the display
  digitalWrite(7, HIGH); --> you meaned the Ethernet shield 2   digitalWrite(10, HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}

Ok. Now use that same code and add the SD.begin() call after starting the Ethernet.

Okay maybe i got something. In the SD Library i found: SPI_HALFL_SPEED uint8_t const SPI_HALF_SPEED = 1; /** Set SCK rate to F_CPU/8. Sd2Card::setSckRate(). */

And in my Ethernet2 Library: SPI.begin(SPI_CS); // Set clock to 4Mhz (w5500 should support up to about 14Mhz) // SPI.setClockDivider(SPI_CS, 255); //7SPI.setClockDivider(SPI_CS, 22); // 14 Mhz, ok // SPI.setClockDivider(SPI_CS, 3); // 28 Mhz, ok SPI.setClockDivider(SPI_CS, 22); // 42 Mhz, ok SPI.setDataMode(SPI_CS, SPI_MODE0);

If i'm using HALF_SPEED the Pictures get Load but my IP is random and the Program hangs. Can it be a Problem taht they are working with difference speeds and this makes me the Problem?

The Ethernet library uses SPI.beginTransaction to set all the SPI settings each call. I don't know about your ethernet2 library.

After the new define, saying in Spi.begin(Pin) and using only half_Speed it works now Thanks, SurferTim

//SD-Karte konfigurieren
UTFT_SdRaw myFiles(&myGLCD);
#define SD_CHIP_SELECT_PIN 4 // SD Auswahlpin Chipselect
SdFat sd;
#define USE_SPI_LIB  -->new


void setup() 
{
  nummern_1 = 172; //nummern_1 - nummern_4 stellen der IP
    nummern_2 =17;
      nummern_3 = 17;
        nummern_4 =210;
  nummern_5 = 172; //nummern_5 - nummern_8 stellen des Routers
    nummern_6 =17;
      nummern_7 = 17;
        nummern_8 =1;
  digitalWrite(SD_CHIP_SELECT_PIN,LOW);
    digitalWrite(slaveSelectPin,HIGH);
  IPAddress ip(nummern_1, nummern_2, nummern_3, nummern_4);
    IPAddress gateway(nummern_5, nummern_6, nummern_7, nummern_8);
  myTouch.InitTouch(); //Starten des Touchscreens
  !sd.begin(SD_CHIP_SELECT_PIN, SPI_HALF_SPEED);  // Starten der SD
    Wire.begin(); //Starte I2C
      myTouch.setPrecision(PREC_EXTREME); //setze Präzision auf max
        myGLCD.InitLCD(LANDSCAPE); //Bildschirmmodus Querformat
          myFiles.load(0, 0, 800, 480, "ETH_logo_mHg2.RAW", 1 );  //Datei laden
            delay(3000); //Warten das mHg2 schoen angezeigt wird
         screen1(); //lade Bildschirm1
           SPI.begin(slaveSelectPin);
             analogReadResolution(12);   //Einstellen auf Analogread von 2 hoch 12 also 4096 Werten      
  attachInterrupt(8, screen2, FALLING); //Bildschirm interrupt aktivieren
    Ethernet.begin(mac, ip); //Starte der IP-Einstellungen 
  Udp.begin(8888); //Öffne den Port
    Serial.begin(9600); //Starte uebertragung an den Seriellen Monitor
}