I am having the problem where attempting to use the w5500 ethernet module with a Nucleo STM32F303RE results in a hang/crash on the udp.endPacket command.
I am using the Ethernet library provided in the Arduino IDE. I have had this working working with a Bluepill in the past. I have searched and found similar threads but generally have been related to udp.begin problems, which I do not believe I have.
The UDP message exchange happens exactly once, the message is received and the response is transmitted, but hangs before udp.endPacket can return a value (which I have been sending out the serial port as a debug effort). It has definitely crashed as loop() is no longer looping.
Any help would be appreciated.
Code: Select all
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
// 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\r\n"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// configure SPI
//SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
// start the Ethernet and UDP:
//Ethernet.init(D10); // CS pin
Ethernet.begin(mac, ip);
Udp.begin(localPort);
Serial.begin(115200);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
Serial.println("parsed Packet");
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
Serial.print("begin");
Serial.println( Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()) );
Serial.print("write");
Serial.println( Udp.write(ReplyBuffer) );
Serial.print("end");
Serial.println( Udp.endPacket() );
}
delay(1000);
}