I am trying to interface a W5500 ethernet PHY with the F303RE and am running into a great deal of difficulty. The SPI interface seems to go crazy after udp endpacket() command which appears like a hung/crashed state. Prior to the crashed state, there is data corruption in the values returned from the W5500, see below. By continuing to send UDP packets the combination will sometimes recovery temporarily. In this hung state, the clock pin starts oscillating like mad.
if the endpacket() line is commented out, the program is stable, but single direction traffic isn't helpful.
The exact same code run on a F103 Bluepill works perfectly, so it is not a case of damage to the W5500.
Any help would be appreciated.
Code: Select all
Received packet of size 11
From 192.168.1.114, port 54041
Contents :
hello world
Received packet of size 11
From 192.168.1.114, port 54041
Contents :
hello world
Received packet of size 11
From 192.168.1.114, port 54041
Contents :
hello world
Received packet of size 32
From 114.108.100.32, port 49407
Contents :
hello world
Received packet of size 32
From 0.0.0.32, port 49407
Contents :
hello world
Received packet of size 11
From 192.168.1.114, port 54041
Contents :
hello world
Received packet of size 11
From 192.168.1.114, port 54041
Contents :
hello world
Received packet of size 32
From 0.0.0.32, port 49407
Contents :
hello world
Received packet of size 32
From 0.0.0.32, port 49407
Contents :
hello world
Code: Select all
//#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.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;
[img]
https://photos.app.goo.gl/zBXAkYagfXg3ioR78
[/img]
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
//SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
//SPI.endTransaction();
// start the Ethernet
Ethernet.begin(mac, ip);
// 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
}
// 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) {
Serial.println("Ethernet cable is not connected.");
}
// start UDP
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
}