chipKIT® Development Platform

Inspired by Arduino™

SPI + SD card issues

Created Thu, 05 Jan 2012 02:22:50 +0000 by rasmadrak


rasmadrak

Thu, 05 Jan 2012 02:22:50 +0000

Hi there,

I'm having weird issues with the SPI + SD card libraries on my Max32. It's connected as follows:

SD card: Center pins (J13) + pin 12 for SlaveSelect.

Display: Edge pins (J8) 51,52,53 for SlaveSelect + pins 46, 47, 48 and 49 for additional data.

If I use them separately both work just fine. When I try to run them after one another it doesn't work. If I comment out the lines "pinMode(48, OUTPUT)" and "pinMode(49, OUTPUT)" the SD card starts working, but the display fails (since it needs those two).

It's really annoying me... :S Any clues on what could be wrong?


Jacob Christ

Thu, 05 Jan 2012 07:14:32 +0000

Hard to say without seeing more code / knowing what display you are using. My best guess is that you are leaving both chip selects low at the same time. The other common SPI issue is clock phase and polarity. Make sure they are correct for both devices.

Jacob


rasmadrak

Fri, 06 Jan 2012 17:00:34 +0000

That's the weird thing - When I'm connecting them one at a time, the same setting works for both devices. I've been careful to only have the active device low when testing.

The thing that does make a difference is commenting out the pinMode commands for two of the additional (non SPI) pins... it probably only works because the display stops working etc...


Jacob Christ

Fri, 06 Jan 2012 17:04:34 +0000

Is one of the devices continuing to drive the MISO line mucking up communications? Several years back I bang my head against the a wall for a month trying to figure out why an EEPROM chip wasn't working and the issue was the SDO line out of a DAC was held high even when the chip select for the device was not asserted.

Jacob


rasmadrak

Fri, 06 Jan 2012 18:34:14 +0000

Might be. Your reply got me thinking: Maybe I could "de-pinMode" the pins by setting the 48 and 49 pin as inputs instead, and guess what? It works.

I don't know why, but setting the totally unrelated pins 48 and 49 to inputs before re-opening the SD card seem to work...

From what I can see in the pinlayout, there shouldn't be any conflicts using 48 and 49 + SPI together with 12 + SPI.

Beats me, but at least it's up and running now - and hopefully will continue to do so in the future.. :S


rasmadrak

Mon, 09 Jan 2012 23:46:06 +0000

Scratch everything - My problem was that I was calling SD.begin() multiple times. If I only call it once and leave it at that it works flawlessly by simply pulling the SS pin LOW for that SD card reader. Either that or the remade cable I made.

Now if only I could get better speed, my current speeds are: Open a file, without doing anything else: 11 ms Reading 512 bytes from that file: 5 ms

11 ms just to open a file seems a long time! And the performance of the reading isn't exactly blistering at 102 KB/sec.

Is there any way to speed up the opening of a file? The file names to read will always be known, and they could all be placed under root etc...