LoRa inAir9 or Dragino and SD card

Hi,

I have a Dragon LoRa 1.3 shield hooked up to an Arduino Mega. The Mega also has an SD card breakout with pin 53 as chipSelect pin. The Dragino shield uses pin 10 as chipSelect. The Dragino shield and code by itself work like a charm, so does the SD breakout and code. But when I hook both of them up together, the SD card can not be initialized most of the time (sporadically it works). I have the feeling as if the two things interfere with each other and have done some googling, but can't lay my hand on what I am doing wrong. Any ideas?

can't lay my hand on what I am doing wrong. Any ideas?

The most obvious thing you did wrong was to not post your code.

PaulS:
The most obvious thing you did wrong was to not post your code.

Fair point. The code is quite long, as I am using GitHub - tftelkamp/arduino-lmic-v1.5: IBM LMIC v1.5 (LoRaWAN in C) adapted to run under the Arduino environment together with http://github.com:adafruit/SD - I will try and compile an example that shows the problem and then post here again.

Always disable all SPI devices before starting any of them.

void setup() {
  // disable Dragino SPI 
  digitalWrite(10, HIGH);
  // disable SD SPI
  digitalWrite(53, HIGH);

  // rest of your setup

Thank you!

The code is here: https://gist.github.com/joscha/6c14414b464d5367f576531166636d08

It uses GitHub - matthijskooijman/arduino-lmic: This library is deprecated, see the README for alternatives. and works fine until the SD card breakout is connected to 50,51,52,53 with 53 being the CS pin.

Even when setting

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

the LoRa shield can't be initialized any more. The LoRa shield has the chipSelect on 10 and the MISO/MOSI/SCK of the ICSP is used.

Is there any chance the SD breakout might not respect the CS pin? Can I test this somehow?

Some SD card readers do not share the SPI bus. Can you post a link to your SD card reader?

SurferTim:
Some SD card readers do not share the SPI bus. Can you post a link to your SD card reader?

That's probably what it is - I thought I might burn some hardware whilst prototyping, so u got these: Micro SD card mini TF card reader module SPI interfaces with level converter chip for arduino

http://s.aliexpress.com/NbEVBFJZ

That looks like a suspect card. If that is a Catalex design, which it appears to be, all lines go through that logic level converter, including the MISO line. In early models, the output enable (OE) for the MISO line was connected to ground. That made the MISO line always active, and would not release the MISO line to allow other devices to use the SPI bus. In newer models, the MISO OE is connected to the CS pin, so it will release the MISO line when the CS (slave select) is taken HIGH.

The only difference between the two is the one circuit board trace.

Thank you so much! What a pity - this has taken me hours over hours. I guess I'll just bin them. Is there any particular microSD card breakout that you can recommend?

To be honest, I'm not familiar with any of the SD card readers. I dislike recommending anything I haven't tried, or at least heard from other users that they work ok.

Good!

I found a work-around, at least for my issue. I need to read configuration settings from an SD card during setup. Then I do not read the card any more. So I added a small relay to my system and power the SD card via the relay.
Upon startup, I do the following:

pinMode(SDPowerPin, OUTPUT);
digitalWrite(SDPowerPin, HIGH);
delay(1000);
// read the data from the card that I need.
// then turn the poser off to the card.
digitalWrite(SDPowerPin, LOW);
delay(1000);
// then call the initialization for the dragino LORA logic


As long as there is no power to the SD card when you initialize the Dragino, it works fine.

I hope this helps you.