chipKIT® Development Platform

Inspired by Arduino™

Fubarmini Mini and SPI.cpp

Created Sun, 22 Dec 2013 02:10:58 +0000 by helpme


helpme

Sun, 22 Dec 2013 02:10:58 +0000

Greetings,

I am trying to get a sketch to compile that indirectly uses SPI, which causes SPI.cpp in the .../hardware/pic32/library/SPI directory to compile. I get the following error messages:

SPI.cpp:65:65: error: '_SPI_MISO_PIN' was not declared in this scope
SPI.cpp:65:80: error: '_SPI_MOSI_PIN' was not declared in this scope
SPI.cpp:65:95: error: '_SPI_MISO_IN' was not declared in this scope
SPI.cpp:65:109: error: '_SPI_MOSI_OUT' was not declared in this scope

I understand that due to the Peripheral Pin Select the identity of these pins are nolonger constant in the build process. I just do not see how these #define(d) variables are supposed to be set. How are these variable intended to be set?

mpide-0023-linux32-201311118-test

Since the constructor for the SPIClass takes ppsFunctionType parameters for the MISO and MOSI parameters, I assume that there are potentially more than one SPI hardware units on the Fubaruino Mini. Which ppsFunctionType value should be used for MISO and MOSI?, PPS_IN_SDI1 and PPS_OUT_SDO1, respectively?

I have noticed that the SS and SCK pins are not mapPps(ed)? Given my naivete with SPI I assume the Master does not need the SS pin, albeit the SPIClass::begin method uses the SS pin and does not configure it using mapPps. Should the SCK pin be configured using mapPps by SPIClass::begin?

Suggestion: Would it be an easier on the newbie and more flexable design to make these parameters to the begin method with defaults to the most commonly used pins?

Thanks,

Fred


majenko

Sun, 22 Dec 2013 13:57:04 +0000

The pin settings are missing from the file they should be in. They should be defined in the Board_Defs.h file within the variant for the Mini.

#define _DSPI0_MISO_IN      PPS_IN_SDI2
#define _DSPI0_MISO_PIN     0
#define _DSPI0_MOSI_OUT     PPS_OUT_SDO2
#define _DSPI0_MOSI_PIN     6

0 is MISO, 4 is CLK and 6 is MOSI.


majenko

Sun, 22 Dec 2013 14:00:23 +0000

I have added the changes to my currently open pull request. It should be live in the next build.


helpme

Sun, 22 Dec 2013 18:13:02 +0000

Thanks for the quick reply and the information.

From your stated #define(s) and the use of these in the DSPI.cpp file, should I assume that I should be using DSPI instead of SPI. If so, is there documentation what DSPI is and how to switch from DSPI to SPI. If not, should the same changes be made for the SPI #define(s)? (I assume the same values should be used.)

Thanks,

Fred


majenko

Sun, 22 Dec 2013 19:41:44 +0000

I am not sure if SPI deals with the PPS or not.

To switch to DSPI just use:

#include <DSPI.h>

DSPI0 SPI;

And then pretty much continue as per normal.

SPI.begin();
x = SPI.transfer();

... etc ...


helpme

Mon, 23 Dec 2013 00:27:24 +0000

Thanks,

The SPI code is where I discovered the PPS issue.

Note: when compiling DSPI.cpp it complained about DSPI1. I noticed that the Board_Defs.h defines _DSPI1_BASE, which DSPI.cpp uses to decide to compile the DSPI1 code, irregardless of NUM_DSPI_PORTS. I wrapped the _DSP1 #define(s) with #if (NUM_DPSI_PORTS > 1) in Board_Defs.h and now DSPI.cpp compiles fine.

Thanks,

Fred


helpme

Fri, 27 Dec 2013 02:54:08 +0000

What pins can we use for the SS?, mostly interested in the using the mini as the master with several slaves; albeit I assume I must make sure the input SS is configured as input and NC. Do we need to use a ppsOutputSelect or a mapPps, (if so what is the ppsFunctionType for a generic digital output pin). Is there documentation on the use of either of these function?

Thanks,

Fred


majenko

Fri, 27 Dec 2013 10:57:40 +0000

As a master you can use any pin as SS. I haven't done any work with DSPI as a slave device though.


helpme

Sun, 05 Jan 2014 19:19:28 +0000

A few followups to my quandaries:

  1. Documentation for the DSPI class(es)/functionality can be had at: [url]http://www.digilentinc.com/Data/Products/12PinCable/Digilent%20chipKIT%20Library%20Reference%20Manuals.zip[/url]

  2. The reason I asked about the SS pin(s) are two fold. 2a) The input SS pin, according to the Arduino SPI documentation, places the SPI functionality into slave mode and prevents mast mode from functioning. Avoiding the physical connection of said pin would prevent this from happening. A particularly nasty bug to track down without the proper equipment. 2b) The documentation for the pin select functionality on the Fubarino Mini suggests that any use of pins need an additional configuration method call to prepare them for use. From experimentation this does not seem to be the case for direct use of the pins. In fact from the end users perspective there is no need to know about the pin select feature, this is handled by the libraries.

Fred