Go Down

Topic: LoRa inAir9 or Dragino and SD card (Read 2080 times) previous topic - next topic

joschafeth

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?

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

joschafeth

The most obvious thing you did wrong was to not post your code.
Fair point. The code is quite long, as I am using https://github.com/tftelkamp/arduino-lmic-v1.5 together with http://github.com:adafruit/SD - I will try and compile an example that shows the problem and then post here again.

SurferTim

#3
Jun 23, 2016, 05:09 pm Last Edit: Jun 23, 2016, 05:11 pm by SurferTim
Always disable all SPI devices before starting any of them.
Code: [Select]
void setup() {
  // disable Dragino SPI
  digitalWrite(10, HIGH);
  // disable SD SPI
  digitalWrite(53, HIGH);

  // rest of your setup
 

joschafeth

Thank you!

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

It uses https://github.com/matthijskooijman/arduino-lmic and works fine until the SD card breakout is connected to 50,51,52,53 with 53 being the CS pin.

Even when setting
Code: [Select]

    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?

SurferTim

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

joschafeth

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

SurferTim

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.

joschafeth

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?

SurferTim

#9
Jun 27, 2016, 02:37 pm Last Edit: Jun 27, 2016, 02:38 pm by SurferTim
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.


allboysbut7

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.

Go Up