W5500 + udp

Тема в разделе "Arduino & Shields", создана пользователем Михаил123, 19 июл 2022.

  1. небольшой код, из примера библиотеки w5500.h, приведенный ниже, не получает пакеты.
    какие есть варианты?

    Код (C++):
    #include <SPI.h>        
    #include <Ethernet_W5500.h>
    #include <EthernetUDP.h>

    // Enter a MAC address for your controller below.
    // Newer Ethernet shields have a MAC address printed on a sticker on the shield
    #if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
    ;
    #else
    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
    #endif

    unsigned int localPort = 8888;      // local port to listen for UDP packets

    IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov NTP server
    // IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov NTP server
    // IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov NTP server

    const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

    byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

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

    unsigned long sendNTPpacket(IPAddress&); // prototype

    void setup()
    {
    // Open serial communications and wait for port to open:
      Serial.begin(9600);
       while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
      }


      // start Ethernet and UDP
    #if defined(WIZ550io_WITH_MACADDRESS)
      if (Ethernet.begin() == 0) {
    #else
      if (Ethernet.begin(mac) == 0) {
    #endif
        Serial.println("Failed to configure Ethernet using DHCP");
        // no point in carrying on, so do nothing forevermore:
        for(;;)
          ;
      }
      Udp.begin(localPort);
    }

    void loop()
    {
      sendNTPpacket(timeServer); // send an NTP packet to a time server

        // wait to see if a reply is available
      delay(1000);
      if ( Udp.parsePacket() ) {
    }
    }