Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Teensy 3.2 + ENC28J60 Strange behavior

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    3

    Teensy 3.2 + ENC28J60 Strange behavior

    Good day to all! I know it's been discussed many times, but I used a search and did not find anything similar to my situation. I need to send and receive a byte array by the UDP packet. For this I use simple program:

    Code:
    #include <UIPEthernet.h>
    #include <SPI.h>
    
    uint8_t myIP[] = { 192, 168, 111, 100 };
    uint8_t sndIP[] = { 192, 168, 111, 200 };
    uint8_t myMAC[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
    
    uint16_t rcvPort = 27000;
    uint16_t sndPort = 27000;
    
    byte sndBuffer[256];
    byte rcvBuffer[256];
    
    EthernetUDP udp;
    
    void setup()
    {
        Serial.begin(115200);
        Ethernet.begin(myMAC, IPAddress(myIP));
        udp.begin(rcvPort);
    
        for(int i=0; i<sizeof(sndBuffer); i++)
        {
            sndBuffer[i] = i;        // just to see something in Wireshark;
        }
    }
    
    void loop()
    {
        udp.beginPacket(IPAddress(sndIP), sndPort);
        udp.write((byte *)sndBuffer, sizeof(sndBuffer));
        udp.endPacket();
    
        Serial.println("Packet Sent");
    
       int packetSize = udp.parsePacket();
    
       if(packetSize > 0)
           Serial.println("Something Received");
    }
    UIPEthernet library https://github.com/UIPEthernet/UIPEthernet

    Compiles without any errors, but I do not receive or send data. When I looked at traffic using Wireshark I saw only ARP requests from ethernet module with reversed IP addresses but normal mac. E.g. he is trying to send to 168.192.200.111 from 168.192.100.111. If I manually reverse sndIP in code like uint8_t sndIP[] = { 168, 192, 200, 111}; I can receive UDP packet from teensy. But if I reverse myIP in Wireshark it becomes as 192.168.1.100 but even on this IP ethernet module do not reply to ping or receive any data.

    I used different ethernet module, different UIPEthernet library, different ArduinoIDE and Teensyduino versions, different OS and PC, all the same. Examples from library also working with the same effect. But a month or two ago everything worked fine. The same library, the same code or any other examples.

    Has anyone encountered such behavior or can give any advice? Thanks!

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,584
    Another thread reported same byte-order problem https://forum.pjrc.com/threads/46196...thernet-Module
    alas, with no solution. The ENC28J60 libraries use a convoluted representation of 4-byte IP address, as two uint16[2] vectors?

    if you look at line 54 in https://github.com/UIPEthernet/UIPEt...Ethernet.h#L54, you can see the conversion from 4-byte IP address to uip represenation. maybe something is amiss with HTONS() ??

    I'd recommend using wiznet 5200 or 5500 and the default arduino/teensy Ethernet lib


    this link http://little-scale.blogspot.com/201...et-module.html suggests a working implementation on T3.2

  3. #3
    Junior Member
    Join Date
    Nov 2017
    Posts
    3
    I did not find that topic, thank you. Yes, the IP address is represented by two uint16 vectors. And yes, I looked into the library code and tried to set the address manually by converting the 4 byte address into two uint16 vectors like this
    Code:
    ip_addr_uip(192 << 8 | 168, 111 << 8 | 200);
    But unsuccessfully.

    I know about Wiznet Ethernet modules and maybe use them in future, but the strangest thing is that before everything worked correctly and there were no problems with byte order.

    Anyway thank you for advice and for your time.

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,584
    Quote Originally Posted by Silenser View Post
    ... but the strangest thing is that before everything worked correctly and there were no problems with byte order.
    Hmmm, "before" what I wonder. The teensy compiler changed to 5.4 not too long ago. if you have older versions of IDE laying around, you could investigate. Maybe some changes to SPI library or the UIPEtherenet lib (does device and library still work on an UNO?). There have been changes to teensy Ethernet lib, but that shouldn't have an effect since you are using UIPEthernet. I don't have ENC28J60 so I can only guess.

  5. #5
    Junior Member
    Join Date
    Nov 2017
    Posts
    3

    Solution

    I tried different versions of Arduino IDE from 1.6.5 and Teensyduino from 1.37 all the same. But finnally got solution. After some experiments I found that macros HTONS() and htons() don't seem to work so after manually changing the code in the part of the translation of the byte order all seems working except DHCP because I can't check it but maybe it works too.

    Here is patched library.

    Thanks for the help!
    Attached Files Attached Files

  6. #6
    Hi All!

    Can you inform me about modifications?
    I would like merge your modifications to my library.

    Best Regards!

  7. #7
    Junior Member fpistm's Avatar
    Join Date
    Jan 2018
    Location
    France
    Posts
    3
    Hi, we met the same issue on Arduino_STM32_Core.
    The issue come from this line:
    utility/uip-conf.h#L125

    Code:
    #define UIP_CONF_BYTE_ORDER LITTLE_ENDIAN
    should be
    Code:
    #define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN
    I've submitted the patch to the UIPEthernet github:
    Fix #22 endianness issue

  8. #8
    Hi All!

    I modified endianness configuration in the code.
    Please download actual version
    https://github.com/UIPEthernet/UIPEt...ive/master.zip
    and try it.

    Best Regards

  9. #9
    Junior Member fpistm's Avatar
    Join Date
    Jan 2018
    Location
    France
    Posts
    3
    tested the 2.0.5 release. it's ok. Thanks

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,325
    Awesome this finally has been fixed.

  11. #11
    Junior Member fpistm's Avatar
    Join Date
    Jan 2018
    Location
    France
    Posts
    3
    Quote Originally Posted by PaulStoffregen View Post
    Awesome this finally has been fixed.
    Oh sorry, I did not test with Teensy, only with some Nucleo boards but it should worked also with Teensy

  12. #12
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,584
    OK, I tested ENC28J60 with T3.2 (SPI clock 20mhz). Everything (ping, TCP, UDP, ARP) seems to be working with latest UIPEthernet lib. More primitive ethercard library is mostly working (limited testing). I updated my Ethernet/WiFi performance tables and power plots.

    https://github.com/manitou48/DUEZoo/...er/wizperf.txt

    https://github.com/manitou48/DUEZoo/...aster/netpower

    Note to Paul: the UIPEthernet lib might be a starting point for Arduino-like Ethernet lib for the T3.5/T3.6 native ethernet. Current testing is with lwIP (polling and callbacks).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •