Teensy 3.2 + ENC28J60 Strange behavior

Status
Not open for further replies.

Silenser

New member
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!
 
Another thread reported same byte-order problem https://forum.pjrc.com/threads/4619...-with-Teensy-3-2-and-ENC28J60-Ethernet-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/UIPEthernet/blob/master/UIPEthernet.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/2016/08/teensy-32-and-enc28j60-ethernet-module.html suggests a working implementation on T3.2
 
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.
 
... 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.
 
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!
 

Attachments

  • UIPEthernet-2.0.4.zip
    305.9 KB · Views: 233
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/blob/master/wizperf.txt

https://github.com/manitou48/DUEZoo/tree/master/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).
 
Status
Not open for further replies.
Back
Top