Hello,
I have been working on troubleshooting an issue that has recently popped up with my M0 Feathers using UDP write and endPacket. I have tried uploading using IDE Version 1.8.5 and 1.8.6 on multiple computers. Both of these sketches run successfully on 32U4 feathers.
The first sketch is a virtually unmodified example sketch ChatServer:
/*
#include <SPI.h>
#include <Ethernet2.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 99, 7, 177);
IPAddress gateway(0, 0, 0, 0 );
IPAddress subnet(255, 255, 255, 0);
// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously
void setup() {
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Chat server address:");
Serial.println(Ethernet.localIP());
}
unsigned long loopCount;
void loop() {
// wait for a new client:
EthernetClient client = server.available();
Serial.print("LC: "); Serial.println(loopCount++);
// when the client sends the first byte, say hello:
if (client) {
if (!alreadyConnected) {
// clead out the input buffer:
client.flush();
Serial.println("We have a new client");
client.println("Hello, client!");
alreadyConnected = true;
}
if (client.available() > 0) {
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);
}
}
}
The ChatServer code works with any of my 32U4 Feathers but does not seem to work with any M0 Feathers. With the M0, the code continues to run but does not read its IP correctly. I can ping the feather successfully. Output below:
Chat server address:0.0.0.0
LC: 0
LC: 1
LC: 2
LC: 3
...
/*
#include <SPI.h>
#include <Ethernet2.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 99, 7, 177);
IPAddress gateway(0, 0, 0, 0 );
IPAddress subnet(255, 255, 255, 0);
// telnet defaults to port 23
EthernetUDP udp;
boolean alreadyConnected = false; // whether or not the client was connected previously
void setup() {
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
udp.begin(4000);
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only
Serial.print("IP address:");
Serial.println(Ethernet.localIP());
}
unsigned long loopCount;
void loop() {
if(Serial.read()=='t')
{
uint8_t emptyPack[] = {0, 0, 0, 0};
Serial.print("BEGIN: "); Serial.println(udp.beginPacket(IPAddress(10, 99, 7, 9), 8888));
Serial.print("WRITE: "); Serial.println(udp.write(emptyPack, 4));
Serial.print("END: "); Serial.println(udp.endPacket());
}else if(loopCount++ % 1000 == 0)
Serial.println(loopCount);
delay(1);
}
On the 32U4s, i get the expected 4 returned from udp.write() and a 1 from udp.endPacket. On the M0, the sketch freezes after endPacket(). The output of this sketch is as follows:
IP address:0.0.0.0
1
1001
2001
3001
4001
5001
6001
BEGIN: 1
WRITE: 0
END:
I am able to ping the IP of the feather before and after the code stops on udp.endPacket() after sending a 't'.
I even had a coworker try a sketch that had been working, and we are seeing the same result where the Feather does not return its IP Address, returns a Zero for udp.write() and blocks code on endPacket.
The outputs posted are with the most up to date libraries (besides SAMD Boards by Adafruit which is at 1.2.2). They were tested on several M0 and 32U4 feathers/Ethernet featherWings. I briefly plugged in an oscilliscope and can confirm that MISO and MOSI are at least active and PIN 10 seems to be working as SS.
I am completely stumped and was very surprised that I couldn't find anyone else posting about the same issue! I would greatly appreciate it if anyone can help, please let me know if any more info is needed!