Teensy 4.1 Ethernet Link Status Always ON, even with no cable

timevdo

New member
When I use a Teensy 4.1 with the UDPSendReceiveString example, I get a strange issue where the Ethernet.linkStatus() returns LinkON regardless of whether or not there is an Ethernet cable plugged in, and then fails to receive any UDP packets. The issue persists with no cable and with no Ethernet shield at all. For debugging purposes, I am testing with the UDPSendReceiveString example, and powering the teensy via USB with no peripherals plugged in. However, the same teensy is being used in a more complex project where the teensy is powered by external power supply. The puzzling thing is that when I try to use the QNEthernet library, I get the same issue - it's specific to the board, not to the software it's running.

Has anyone encountered this issue before, or have any ideas on how to fix this? If it is a hardware issue, is it fixable or is the teensy permanently networkless? I have had more than one teensy develop this issue seemingly at random after working for months. The teensy appears fully functional apart from the network isssue.

Code:
#include <NativeEthernet.h>
#include <NativeEthernetUdp.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged";        // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
  
  // Open serial communications and wait for port to open:
    Serial.begin(9600);
    while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
    }


  Serial.print("Link 1: ");
  Serial.println(Ethernet.linkStatus()); //Prints 2 = LinkOFF, as expected

  // start the Ethernet
  Ethernet.begin(mac, ip);

  Serial.print("Link 2: ");
  Serial.println(Ethernet.linkStatus()); //prints 1 = LinkON, even with no cable plugged in

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    //This statement should print but doesn't when I test with no cable
    Serial.println("Ethernet cable is not connected.");
  }

  
  Serial.print("Link 3: "); //prints 1 = LinkON, even with no cable plugged in
  Serial.println(Ethernet.linkStatus());

  // start UDP
  Udp.begin(localPort);

  Serial.println("Done!");
}

//UDP code...
 
Last edited:
Back
Top