I really need help with my SPI devices and arduino mega 2560 :(

I am having trouble initializing my 3 SPI devices, a micro sd card module, usb host shield and RA8875.
The connection is sd_cs 4, RA8875_cs 5 and usb_cs 10. Here is my setup function.

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

pinMode(10,OUTPUT);
digitalWrite(10, HIGH);

pinMode(5,OUTPUT);
digitalWrite(5, HIGH);

pinMode(4, OUTPUT);
digitalWrite(4, HIGH);

digitalWrite(5, LOW);
Serial.println("RA8875 start");

//RA8875 initialize
if (!tft.begin(RA8875_800x480)) {
Serial.println("RA8875 Not Found!");
while (1);

}

Serial.println("Found RA8875");

//sd card initialize
digitalWrite(4, LOW);
if (!SD.begin(4)) {
Serial.println("SD initialization failed!");
return;
}
Serial.println("SD initialization done.");
digitalWrite(4, HIGH);

//usb initialize
digitalWrite(10,LOW);
delay(20);
digitalWrite(10,HIGH);
#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
Serial.println("Start USB");

if (Usb.Init() == -1)
Serial.println("OSC did not start.");
else
Serial.println("USB ready!");

digitalWrite(10,HIGH);
delay( 200 );
}

the ra8875 and sd card are fine but the usb host have an output "OSC did not start''
I really need help please :frowning:

Can you get each of them to work on its own?

What about the pair of ra8875 and the USB Host without the SD Card?

There have been other Threads about problems with the SD Card library and other SPI devices.

And please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Make sure you post a complete program.

…R

Yes sir, the three used to work together but sometimes the initialization failed and restarting the module fixes it then after a couple of reset it will fail again so I decided to search about SPI then I learn about the SS then it fixes the sd card and ra8875 initialization but the usb host still failing.

magicgreenhalaman:
Yes sir, the three used to work together but sometimes the initialization failed and restarting the module fixes it then after a couple of reset it will fail again so I decided to search about SPI then I learn about the SS then it fixes the sd card and ra8875 initialization but the usb host still failing.

I can't relate that to my questions in Reply #1.

Could you answer each of my questions separately.

Also tell us what you did when you "leanred about the SS"

...R