Teensy 4.1 NativeEthernet Link Status

Hello,

I recently purchased the Ethernet Kit for the Teensy 4.1 and I have been trying to check the link status of the device as just a first test to getting the device working. I went to the examples folder and found the NativeEthernet > LinkStatus sketch and uploaded that without any changes but for some reason no matter what cable or device I plug into it the link status says "OFF" in the serial monitor. Where should I start looking to debug this issue? I figured that running the Link Status example sketch would have been the best place to start but even that doesn't seem to be working. Any insight would be greatly appreciated.

Thanks!
 
For future readers, here's a basic "QNLinkStatus" example that uses the QNEthernet library. Note that it will run without putting anything in loop().

Code:
#include <QNEthernet.h>

using namespace qindesign::network;

void setup() {
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
    // Wait for Serial
  }
  stdPrint = &Serial;  // Make printf() work, a QNEthernet feature

  printf("Starting...\r\n");

  // Print the MAC address
  uint8_t mac[6];
  Ethernet.macAddress(mac);  // This is informative; it retrieves, not sets
  printf("MAC = %02x:%02x:%02x:%02x:%02x:%02x\r\n",
         mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

  // Listen for link changes
  Ethernet.onLinkState([](bool state) {
    printf("[Ethernet] Link %s\r\n", state ? "ON" : "OFF");
  });

  // Listen for address changes
  Ethernet.onAddressChanged([]() {
    IPAddress ip = Ethernet.localIP();
    bool hasIP = (ip != INADDR_NONE);
    if (hasIP) {
      IPAddress subnet = Ethernet.subnetMask();
      IPAddress broadcast = Ethernet.broadcastIP();
      IPAddress gw = Ethernet.gatewayIP();
      IPAddress dns = Ethernet.dnsServerIP();

      printf("[Ethernet] Address changed:\r\n"
             "    Local IP     = %u.%u.%u.%u\r\n"
             "    Subnet       = %u.%u.%u.%u\r\n"
             "    Broadcast IP = %u.%u.%u.%u\r\n"
             "    Gateway      = %u.%u.%u.%u\r\n"
             "    DNS          = %u.%u.%u.%u\r\n",
             ip[0], ip[1], ip[2], ip[3],
             subnet[0], subnet[1], subnet[2], subnet[3],
             broadcast[0], broadcast[1], broadcast[2], broadcast[3],
             gw[0], gw[1], gw[2], gw[3],
             dns[0], dns[1], dns[2], dns[3]);
    } else {
      printf("[Ethernet] Address changed: No IP address\r\n");
    }

    // Possibly tell interested parties the state of the IP address
    // here, for example, servers, SNTP clients, and other sub-programs
    // that need to know whether to stop/start/restart/etc
    //addressChanged(hasIP);
  });

  // Start using DHCP (non-blocking)
  if (!Ethernet.begin()) {
    printf("ERROR: Failed to start Ethernet\r\n");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}
 
Back
Top