Teensy 4.1 SPI1 for WiFi101 - has anything changed?

Vincefarq

Member
Hi there. I just tried to compile some code I wrote for Teensy 4.1 and a WINC1500 on SPI1. I hadn't changed anything since it ran perfectly on Arduino 1.8.19 and Teensyduino 1.59. Now I'm using Arduino 2.3.4 with Teensyduino and I can't get the WINC1500 to work on SPI1 at all. i just get the error message "WiFi shield not present". Can someone please offer some guidance?

First, I made sure I updated the WINC1500 Firmware to 19.6.1

I've even stepped down to testing the WiFi101/ScanNetworks example to test the bare minimum. I made sure I got ScanNetworks to work on SPI first, then switched to SPI1.

I made sure I edited C:\Users\[USERNAME]\Documents\Arduino\libraries\WiFi101\src\bus_wrapper\source\nm_bus_wrapper_samd21.cpp as Paul suggested in this thread: https://forum.pjrc.com/threads/47076-Do-SPI1-and-SPI2-of-Teensy-3-6-work

Code:
#if !defined(WINC1501_SPI)
  #define WINC1501_SPI SPI1
#endif

Here's my test code of ScanNetworks on SPI1

Code:
/* notes and attrib removed for clarity */

#include <SPI.h>
#include <WiFi101.h>
void setup() {

  SPI1.setMOSI(26); SPI1.setMISO(1); SPI1.setSCK(27); // teensy 4.1 SPI1 bus pins
  SPI1.begin(); // removing this seems to make no difference
  WiFi.setPins(8,7,4); //WiFi.setPins(chipSelect, irq, reset, enable) but enable is currently tied to VIN for now

  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
  // Print WiFi MAC address:
  printMacAddress();
  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}
void loop() {
  delay(10000);
  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}
void printMacAddress() {
  // the MAC address of your WiFi shield
  byte mac[6];
  // print your MAC address:
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  printMacAddress(mac);
}
void listNetworks() {
  // scan for nearby networks:
  Serial.println("** Scan Networks **");
  int numSsid = WiFi.scanNetworks();
  if (numSsid == -1)
  {
    Serial.println("Couldn't get a wifi connection");
    while (true);
  }
  // print the list of networks seen:
  Serial.print("number of available networks:");
  Serial.println(numSsid);
  // print the network number and name for each network found:
  for (int thisNet = 0; thisNet < numSsid; thisNet++) {
    Serial.print(thisNet);
    Serial.print(") ");
    Serial.print(WiFi.SSID(thisNet));
    Serial.print("\tSignal: ");
    Serial.print(WiFi.RSSI(thisNet));
    Serial.print(" dBm");
    Serial.print("\tEncryption: ");
    printEncryptionType(WiFi.encryptionType(thisNet));
    Serial.flush();
  }
}
void printEncryptionType(int thisType) {
  // read the encryption type and print out the name:
  switch (thisType) {
    case ENC_TYPE_WEP:
      Serial.println("WEP");
      break;
    case ENC_TYPE_TKIP:
      Serial.println("WPA");
      break;
    case ENC_TYPE_CCMP:
      Serial.println("WPA2");
      break;
    case ENC_TYPE_NONE:
      Serial.println("None");
      break;
    case ENC_TYPE_AUTO:
      Serial.println("Auto");
      break;
  }
}
void printMacAddress(byte mac[]) {
  for (int i = 5; i >= 0; i--) {
    if (mac[i] < 16) {
      Serial.print("0");
    }
    Serial.print(mac[i], HEX);
    if (i > 0) {
      Serial.print(":");
    }
  }
  Serial.println();
}

Is there something I'm missing? After fighting this problem for three days, I'd appreciate any help I can get.

Thank you,

-Vince
 
Last edited:
Welp. I think I have a clue. I'm able to get the above code running on an old computer with Arduino 1.8.16 and the latest WiFi101 library straight from a GitHub zip. IDE 1.8.16 didn't have a library manager. On Arduino 2.3.4 it fails.

Strangely enough, 2.3.4 seems to be ignoring my nm_bus_wrapper_samd21.cpp changes. I can even delete that file without getting any compiler complaints. I'm going to remove all traces of 2.3.4 and try a fresh install of the relevant libraries.
 
Okay I fixed it. I noticed that I could delete the entire WiFi101 library folder without compiler complaints. I did a search for all things WiFi101/ATWINC1500 on my system and could not find any copies that the IDE was using. I just decided to go nuclear and remove all traces of the IDE using the steps on this thread: https://forum.arduino.cc/t/how-can-...ll-remnants-of-an-arduino-ide-install/1198801

Then I reinstalled 2.3.4, the WiFi101 library, and Teensyduino. I updated the nm_bus_wrapper_samd21.cpp and everything works fine now. The phantom library is still a mystery, but I'll be watchful in case this issue returns.

-Vince
 
Back
Top