Do SPI1 and SPI2 of Teensy 3.6 work?

Status
Not open for further replies.

MickPF

Member
Hello,

I try to use these SPI's and can't get them running.
I use Arduino 1.8.4 (and 1.8.5) with Teensyduino.
I've connected digital signals
0 to MOSI
1 to MISO
31 to CS
32 to SCK
and used the
Code:
<...>
#define WINC1501_SPI	SPI1
#include <WiFi101.h>
#include <WiFiUdp.h>

#include <NTPClient.h>
<...>
/*
 * Following definitions work with 'SPI'
 * but are reserved for an other SPI device (TFT display)
 */
//#define WIFI_MOSI_PIN	  11
//#define WIFI_MISO_PIN	  12
//#define WIFI_SCLK_PIN	  13
//#define WIFI_CS_PIN	  15
/*
 * Following definition DO NOT work either with 'SPI1' nor with 'SPI2'
 */
#define WIFI_MOSI_PIN	   0
#define WIFI_MISO_PIN	   1
#define WIFI_SCLK_PIN	 32
#define WIFI_CS_PIN	 31
/*
 * Following definitions work with 'SPI' and should work with other SPI buses
 */
#define WIFI_EN_PIN	 24
#define WIFI_IRQ_PIN	 25
#define WIFI_RST_PIN	 26
#define WIFI_WAKE_PIN    27
<...>
void setup()
{
<...>
/*
 * Setup SPI-0 bus for the TFT display with touchscreen
 * Status: OK (working)
 */
	pinMode(TFT_CS_PIN, OUTPUT);
	pinMode(TFT_DC_PIN, OUTPUT);
	pinMode(TFT_RST_PIN, OUTPUT);
	brightness = 255;
	pinMode(TFT_BL_PIN, OUTPUT);
	analogWrite(TFT_BL_PIN, brightness);
	SPI.setMOSI(TFT_MOSI_PIN);
	SPI.setMISO(TFT_MISO_PIN);
	SPI.setSCK(TFT_SCLK_PIN);
	SPI.begin();
/*
 * Setup SPI-1 bus for the WiFi module
 * Status: FAILED
 */
 	pinMode(WIFI_MOSI_PIN, OUTPUT);
 	pinMode(WIFI_MISO_PIN, INPUT);
 	pinMode(WIFI_SCLK_PIN, OUTPUT);
	pinMode(WIFI_CS_PIN, OUTPUT);
	pinMode(WIFI_EN_PIN, OUTPUT);
	pinMode(WIFI_IRQ_PIN, INPUT);
	pinMode(WIFI_RST_PIN, OUTPUT);
	pinMode(WIFI_WAKE_PIN, OUTPUT);
	SPI1.setMOSI(WIFI_MOSI_PIN);
	SPI1.setMISO(WIFI_MISO_PIN);
	SPI1.setSCK(WIFI_SCLK_PIN);
	SPI1.begin();
	WiFi.setPins(WIFI_CS_PIN, WIFI_IRQ_PIN, WIFI_RST_PIN, WIFI_EN_PIN);
<...>
}

I've also replaced SPI1 with SPI2, but nothing improved the result: Digital pins 0, 1 and 32 are dead (inspected with a multichannel oscilloscope).
Signals on pins 31 (CS), 24 (EN), 25 (IRQ), 26 (RST) and 27 (WAKE) are OK and work.
The WiFi module works with SPI on pins 15 (CS), 11 (MOSI), 12 (MISO) and 13 (SCK).

Do I something wrong?

Please help me...

Thanks in advance,
Michael
 
I am assuming you are using the SPI library? As you are using the setMOSI... functions which are not part of I2C_t3 library.

You don't need to do all of the pinMode(..., OUTPUT) of the main SPI pins (MOSI, MISO, SCK), they will be set to SPI mode (ALT 2) by the SPI1.begin function.
It looks like you are using the default SPI1 pins, so you probably don't need the set Pin functions either.

What I don't know is how the Wifi library you are specifying above works with SPI1...
Not sure which library this is... If I search for wifi101 in my Teensyduino install, I see two test apps include these for some Arduino SAMD boards like:
Code:
#if defined(ARDUINO_SAMD_ZERO)
    #include <WiFi101.h>
    #include <WiFiUdp.h>
#else
    #include <Ethernet.h>
    #include <EthernetUdp.h>
#endif

What version of Teensyduino are you running? The other multiple SPI buses were only added in later versions of Teensyduino. I assume you are again running these as you did not mention compile errors
 
Well, did you modify the Wifi101 library to use SPI1?

This line will not work if only in your program.

Code:
#define WINC1501_SPI	SPI1

It doesn't matter if you define this in your code. Doing so changes nothing in the actual library. The change need take effect here:

https://github.com/arduino-librarie..._wrapper/source/nm_bus_wrapper_samd21.cpp#L53

Probably the simplest thing to do is edit that file and change SPI to SPI1 on line 54.

When they say "Variants may define an alternative SPI instace", that means the files like Arduino.h or SPI.h. But it does not mean your code you edit in the Arduino IDE. This needs to be set in that library file, or in one of the headers it actually includes.
 
Hello,

@Paul: You are right! Your suggestion works.
I don't really understand, why my definition of "WINC1501_SPI" has no effect, but it's OK to me.
I don't see any possibility to define it in the compiler command line by "-D..." for this project only. Do you have any idea?
BTW. I use the latest released version of the Ardiuno IDE and Teensyduino.

Thanks a lot for your help.
 
You are somewhat on the right track with -D during the build, any change has to be made at the time that library unit is compiled. Putting it only in your current sketch does not reach into the library when it is built because it does not 'include' anything from you, like the #define.

There is a thread on defs.h by FrankB that alters the build control files with a couple lines to have them all include the defs.h file from local sketch directory, though I'm not sure that would help here with what is needed.
 
Status
Not open for further replies.
Back
Top