Sd Card and Lora on the same spi bus

Hi everyone,
this is the first time that i use this board and i recentely started to work on an existing project for my company.
I have to write an sd card driver but i can’t make SDCard and LoRa work togheter, my configuration is:

LoRa SDCARD
CS 18 CS 27
SCK 5 SCK 5
MISO 19 MISO 19
MOSI 27 MOSI 27

i put a pullup resistor (1.5k) between sd cs and VCC , another one between lora cs and VCC.

I have the GPIO 17,23,25 and 36-39 free, i tried to use these but everything i put on GPIO 36/39 didn’t work, i know that are only input ports, maybe there is some workaround to let them work?)

i found some solution (like that), but nothing work.

surely i’m making a lot of mistakes, but i have no time to study all the architecture (long story) .

the code is

#include <lmic.h>
#include <SPI.h>
#include <SD.h>
const lmic_pinmap lmic_pins = {
.nss = 18,
.rxtx = LMIC_UNUSED_PIN,
.rst = 14,
.dio = {26, 34, 35}, // Heltec WiFi LoRa Board V2 (34,35) ; Heltec WiFi LoRa Board V1 (32,33)
.rxtx_rx_active = 0,
.rssi_cal = 8, // This may not be correct for Heltec board
.spi_freq = 8000000,
};
#define SD_CS 27
#define SD_SCK 5
#define SD_MISO 19
#define SD_MOSI 27
SPIClass spi1;
void setup()
{
// LMIC iniyt
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
SPIClass (1);
spi1.begin(SD_SCK,SD_MISO,SD_MOSI,SD_CS);
if(!SD.begin(SD_CS,spi1)){
Serial.println(“Card Mount Failed”);
}
}

thanks for help

When using SPI with lora, you need to be aware that lora will sleep, and the program will not run again.

Thanks for reply,
I solved this by using the mySD.h library, this is the modified code (maybe someone need this).

#include <mySD.h>

pinMode(SD_CS,OUTPUT);
digitalWrite(SD_CS,DeSelect);
pinMode(18,OUTPUT);
digitalWrite(18,DeSelect);
digitalWrite(SD_CS,Select);
if(!SD.begin(SD_CS,SD_MOSI,SD_MISO,SD_SCK)){
Serial.println(“Card Mount Failed”);
}
else
Serial.println(“Card Mounted!”);
digitalWrite(SD_CS,DeSelect);
digitalWrite(18,Select);

where 18 is the Lora Cs pin.
If i use the SD library and SPI init the card can’t mount :sweat:

EDIT: BTW, the card now mount 3 on 10 attempts, i have to shutdown the board to try to recover…is not very stable. I don’t think it’s notmal, maybe i miss something.