chipKIT® Development Platform

Inspired by Arduino™

SPI + SD problem

Created Thu, 06 Sep 2012 10:52:21 +0000 by Vittorio


Vittorio

Thu, 06 Sep 2012 10:52:21 +0000

Hi, I'm using the SPI of a max32 to drive some oled screens and to read an SD card. all the devices are in parallel (sharing MISO, MOSI, CLOCK).

The project was developed first on the arduino MEGA and now ported on the max32.

I have noticed that, after using the SD card (called SD.begin() and read sucesfully a file) the SPI should be initialized again in order to work.

There was also a strange glitch associated with this: after several initialization of the SD card and the SPI bus i start to get errors in reading the files.

is this a bug? am I doing something that is beyond the specifications of the SD and the SPI libraries?

V.


rasmadrak

Thu, 06 Sep 2012 11:46:35 +0000

You should only have to call SD.begin() once during setup. Make sure each slaveSelect is correct and that the hardware ss pin remains correct even if you're not using it (or if you are).

There can be problems running the SD card along with other devices on the same SPI. I suggest you change your other devices (not the SD) to use DSPI (SPI1 -> SPI3) instead. This is what I'm currently doing and it helps a lot! SD card on SPI0 (regular SPI) and the display on SPI1.

That way you can use separate clocks and doesn't have to toggle the SS select's. You can also use the hardware SS for the SD card.


majenko

Fri, 07 Sep 2012 00:07:57 +0000

The SD card's SPI interface is non standard and breaks the specifications. There are parts of the protocol which involve generating clock pulses while the chip select is high. This stops it working nicely with other SPI devices on the same bus.

An SD card should really be used with a dedicated SPI bus, so it doesn't interfere with other decices.


Vittorio

Tue, 11 Sep 2012 10:09:13 +0000

thanks for the reply.

The SD card's SPI interface is non standard and breaks the specifications. There are parts of the protocol which involve generating clock pulses while the chip select is high.

you opened my eyes :shock:

I suggest you change your other devices (not the SD) to use DSPI (SPI1 -> SPI3) instead.

it would make sense - is there an interface to it ready for mpide or have I to make a modified version of the SPI.h and SPI.cpp to write in a different register?


rasmadrak

Tue, 11 Sep 2012 18:37:50 +0000

No, let the SD card use the old SPI and use the DSPI-library ( #include <DSPI.h> ) instead for your other devices.