Feather M0 fails when an SD card is inserted. LMIC problem - radio.c:923

Hi there,

I manage to use an Adafruit feather M0 adalogger and Adafruit feather LoRa wing radio ( RFM95 with SX1276) to upload data to TTN. I used the example provided in the LMIC library (arduino-lmic/examples/ttn-otaa-feather-us915-dht22 at master · mcci-catena/arduino-lmic · GitHub).

I only modified the pin mapping to match my project:

const lmic_pinmap lmic_pins = {
    .nss = 10,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 13,
    .dio = {12, 15, LMIC_UNUSED_PIN},
    .rxtx_rx_active = 0,
    .rssi_cal = 8,              // LBT cal for the Adafruit Feather M0 LoRa, in dB
    .spi_freq = 8000000,
};

Up to here, everything works perfect! As indicated by this tutorial: Region Configuration | Using LoraWAN and The Things Network with Feather | Adafruit Learning System

The problem comes when I insert an SD card. I need an SD card in my proyect to log the data i send to the TTN. However, just inserting the card causes the program to fail. I get the following error int he Serial monitor:

FAILURE
C:\Users\user\Documents\Arduino\libraries\MCCI_LoRaWAN_LMIC_library\src\lmic\radio.c:923

The feather M0 adalogger SD card uses pin 7 as card detect and pin 4 as chip select. As soon as I insert an SD card, both pins (7 and 8) go high. could that be the problem?

Do I have to define that I am using a “user configuration” when it comes to the pin mapping used my LMIC library?

Now, it does not work anymore, even without the SD card. This started to happen after I inserted the SD card. How to know if the radio hardware is OK? What means the error 923??

After some reading, I suspected of a hardware problem. As SD card is also SPI, I used a voltmeter to monitor the LoRa radio CS pin. That solved the problem! At least, while I was holding the multimeter probes on GND and LoRa radio CS pins. How to fix this? Could it be that my SPI frequency is too high? Could the CS pin be bouncing? I do not have at oscilloscope at hand. Considering my setup, it is hard to imagine that it is a hardware problem, but it seems that it is. Here is a picture of my setup: No long wires. Why is this happening this? how to solve it?

Update: I reduced the SPI frequency to 1MHz. Now, I do not get the FAILURE message, but the program does not passes the “Starting” string. Measuring CS pin with the multimeter still fixes the problem. I also tested my setup with the Adafruit M0 Basic proto board. It works just fine! Even at 8 MHZ.

Still looking for a solution.

The problem is probably that the CS pin is active to the radio at the same time it is active to the SD card. Can you check if that might be the case?