chipKIT® Development Platform

Inspired by Arduino™

How to use multiple SPI

Created Thu, 22 Dec 2011 15:42:19 +0000 by Toley


Toley

Thu, 22 Dec 2011 15:42:19 +0000

Is there an example or some help on how to use more than 1 SPI port on the same project. Thank you.


rasmadrak

Fri, 23 Dec 2011 00:30:41 +0000

Hi there!

Yes, there is. Don't know about the quality of this one, but it's one of the first hits on google for "multiple spi tutorial": [url]http://tronixstuff.wordpress.com/2011/06/15/tutorial-arduino-and-the-spi-bus-part-ii/[/url].

Basically, you connect all units to the same SPI connectors and use a unique slave-select pin for each unit. the one unit with the slaveselect low listens to commands, the others ignore.


Toley

Fri, 23 Dec 2011 03:20:38 +0000

Thank you very much but this is not what I am looking for. I need to use at least 2 different SPI bus. The PIC32MX795F512L on the Max32 board have 4 SPI ports, can I use more than 1 ???


KurtE

Fri, 23 Dec 2011 14:47:47 +0000

If it were me, I would probably look at their DSPI library. It looks like their board definitions know about the 4 different SPI channels...

But note, I have not tried this yet.

Kurt


GeneApperson

Tue, 27 Dec 2011 20:15:29 +0000

After doing the board variant work, it didn't look to me that it would be feasible to make the existing SPI library support multiple hardware ports, so I wrote the DSPI library. The DSPI library can support as many hardware SPI ports as the board supports (which may be less than the number that the microcontroller supports due to conflicting uses of pins on some boards).

The standard SPI library only supports byte-at-a time transfers. The DSPI library also does buffered transfers and interrupt driven, buffered transfers.

I'm still working on the programming reference documentation, but it should be out in a few days. I've taken a few days off for the holidays.

Unlike most Arduino libraries, DSPI does not automatically create any object instances. There is an object class defined (DSPI0, DSPI1, DSPI2, etc) for each SPI port supported by the board. The user must declare an object instance for each port to be used.

Gene Apperson Digilent


unexpectedly

Tue, 27 Aug 2013 00:54:07 +0000

Hi, how exactly does a person invoke the DSPI library? I haven't yet found any code examples... the PDF says:

The DSPI library defines an object class (DSPI0, DSPI1, etc.) for each hardware SPI port supported by the board in use. These are used to create one or more object instances used to access the SPI ports. The symbol NUM_DSPI_PORTS is defined for each board and can be used to determine the number of DSPI ports available on the board. To use the DSPI library, an object instance variable of the appropriate DSPIx object class must be created. The object instance is initialized by calling the begin function() and then using other functions to set mode, and clock speed if necessary. Data canthen be transferred to a slave device by calling the various data transfer functions.

In the class's .h file:

DSPI _dspi;

In the .cpp constructor:

_dspi.begin(cs);

Compiler says: [color=#BF0000]D:\Documents\mpide\libraries\DSPI/DSPI.h: In constructor 'AdacK_ST7735::AdacK_ST7735(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)': D:\Documents\mpide\libraries\DSPI/DSPI.h:108:4: error: 'DSPI::DSPI()' is protected [/color]


OK, so now let's try a declaration involving DSPI2 (since my interpretation of the uc32 documentation makes me think that will work for my Arduino shield's pins 10-13).

In the .h:

DSPI2 _dspi;

(same .cpp as above) [color=#BF0000]In file included from Ada_TFT.cpp:5:0: D:\Documents\mpide\libraries\AdacK_ST7735/AdacK_ST7735.h:129:2: error: 'DSPI2' does not name a type [/color]


Let's try this, I've seen those double colons interspersed before... .h file:

DSPI::DSPI2 _dspi;

(same .cpp as above) Compiler: [color=#BF0000]In file included from Ada_TFT.cpp:5:0: D:\Documents\mpide\libraries\AdacK_ST7735/AdacK_ST7735.h:129:2: error: 'DSPI2' in class 'DSPI' does not name a type[/color]

I attached a 7zip.org archive of my code. The Ada_TFT/Ada_TFT.ino sketch is the one I use when I buy the Adafruit 1.8" TFT shield and solder the headers to it. Real simple hello world for the shield. Since it is purely SPI, I see no obstacles to getting this done ... other than my complete inability to read the Digilent chipKIT SPI Library PDF or getting the DSPI.h working.

I'm using Mpide 0032-windows-20130715...

Thanks in advance for any help. Seriously makes me feel dumb compared to my quasi-mastery in the Arduino world.