LCD and screen together

I am trying to use SD card and LCD together with Arduino nano. Their CS and CD pins are different but MISO , MOSI and clk are the same pin 11,12,13. They do the job both perfectly but when I store the data in SD card, it does not return to LCD anymore and freezes. Do you have any solution for this?

Welcome to the forum

Please read the advice given in How to get the best out of this forum and post your sketch using code tags and a schematic of your project showing how the components are connected and powered

just gessing without seeing your sketch: you are running out of memory.

// Sd card
#include <SD.h>
#include <SPI.h>
File file;
#define cardDetect 3
#define CS 4
#define DI MOSI
#define DO MISO
#define CLK SCK // Sd card
//SCREEN
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "Fonts/FreeSans9pt7b.h"
#include "stdlib.h"

#define TFT_DC 9
#define TFT_CS 10
#define TFT_MOSI 11
#define TFT_MISO 12
#define TFT_CLK 13

#define BLACK 0x000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0XF81F
#define YELLOW 0XFFE0
#define WHITE 0xFFFF
#define DKBLUE 0x000D
volatile float filenumber = 0;

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK);//SCREEN

void setup() {
// put your setup code here, to run once:
//SCREEN
Serial.begin(9600);
tft.begin();
tft.setRotation(1);
tft.setTextColor(WHITE);
tft.fillScreen(BLACK);
tft.setCursor(50, 40);
tft.print("test1");
Serial.println("initilaising SD card...");
if (!SD.begin(4)) {
Serial.println("initilaise SD failed...");
if (CS == HIGH)
Serial.println("1");
else
Serial.println("0");
if (TFT_CS == HIGH)
Serial.println("1");
else
Serial.println("0");

digitalWrite (CS, HIGH);
digitalWrite (TFT_CS, LOW);
SPI.setDataMode(SPI_MODE2);
//SPI.setDataMode(SPI_MODE3);
//SPI.setBitOrder(LSBFIRST);
return ;

}
Serial.println("initilaisation successful");
Serial.println("creating file");
filenumber++;
String tempname = (String(filenumber) + (".txt"));
const char *filename = tempname.c_str();
file = SD.open ("filename.txt", FILE_WRITE);

if (file)
{
file.print ("load");

file.close();
Serial.println("file created");

}
else
{
Serial.println("file not created");
}
if (CS == HIGH)
Serial.println("1");
else
Serial.println("0");
if (TFT_CS == HIGH)
Serial.println("1");
else
Serial.println("0");
digitalWrite (CS, HIGH);
digitalWrite (TFT_CS, LOW);
SPI.setDataMode(SPI_MODE2);
//SPI.setBitOrder(LSBFIRST);
tft.fillScreen(BLACK);
tft.setCursor(50, 40);
tft.println(" test2");
}

void loop() {
// put your main code here, to run repeatedly:

}

@sahargemma
please read in the forum how to - how to post code correctly.
please edit your post.

if you have outputs on your serial, post it also (in code tags)

@sahargemma
Did you deliberately ignore the advice to post you code using code tags ?

Which SD and LCD parts? Provide links to the items you obtained for this.

Some SD modules are notorious for not playing nice on the SPI bus…

Does each item work by itself with example sketches or test sketches you wrote?

a7

Yes both SD card and LCD works fine separately. I have used
https://www.mouser.com/datasheet/2/737/adafruit-micro-sd-breakout-board-card-tutorial-932877.pdf
For sd card and
Adafruit 2478, 2.4in Resistive Touch Screen Add On Board for Development Projects
as LCD