Ethernet Interface

I posted this question a few months ago in a different forum and received one reply which was confusing.

I want to add Ethernet to my Mega 2560 project. I want the RJ45 to be accessible at the back of my project box extending through the backplate but I would rather not have the 2560 there. A "remote" interface seems to be better for my application than a shield. Any ideas?

I am now at a point in my project where I am ready to implement an Ethernet capability.

One of the devices suggested was the WIZ850io. However, I wrote to their tech support and was informed that it does NOT come with a MAC address. It seems to me that this would make it unusable to the hobbiest community. So I am still looking.

I purchased some short cat6 extension cables from one of the China suppliers a few years back, it is about 10" long with a RJ45 mail on one end and a chassis mount RJ45 female on the other end. I purchased them for a project and they worked great. I do not remember how much but it was not that much. As far as the MAC address you supply it. It simply cannot match anything on your network. A lot of the sample code sets this up.

Do a Google image search for "panel mounted rj45". There are a variety of adaptors that allow the ethernet interface board to be located some distance away from the panel.

Unique hardware pre-assigned MAC addresses are only needed if you don't have control of what other devices will be plugged into the network, for example, a typical office scenario with people randomly plugging in computers, printers etc.

For a hobby application first you do a "site survey" to find out the MAC addresses of every device on your network, then you choose a MAC address that is unique to your network. (Your network router can usually be queried for a list of connected devices and their MAC addresses.)

the Ethernet library sets the MAC address. the examples have a example MAC address

Thank you all for your replies. I did not realize that we are allowed to create our own MAC addresses. After some searching I find that bit 1 in the most significant byte of a MAC address is the U/L bit: 1 = local, 0 = universal.

Now I have another problem/question. I attempted to compile the UPD example: UDPSendReceiveString.ino and I get the following warning:

In file included from C:_MyInstalls\Arduino\libraries\Ethernet\src\Dns.cpp:8:0:
C:_MyInstalls\Arduino\libraries\Ethernet\src\Dns.cpp: In member function 'uint16_t DNSClient::BuildRequest(const char*)':
C:_MyInstalls\Arduino\libraries\Ethernet\src\utility/w5100.h:457:25: warning: result of (256 << 8') requires 18 bits to represent, but 'int' only has 16 bits [-Wshift-overflow=]
#define htons(x) ( (((x)<<8')&0xFF00) | (((x)>>8')&0xFF) )

C:\_MyInstalls\Arduino\libraries\Ethernet\src\Dns.cpp:164:18: note: in expansion of macro 'htons'
twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);

NOTE: the apostrophe after the 8s is due to the emoticon I get without it!

What should I do? I always take warning seriously, it is too easy to ignore a warning and have it bite you later!

k3pto:
What should I do? I always take warning seriously, it is too easy to ignore a warning and have it bite you later!

it is a warning. ignore it

This is really an error in the ethernet library.
The file ...\ Ethernet\src\Dns.cpp contains the following code:

...
#include "utility/w5100.h"
...
#define QUERY_FLAG               (0)
...
#define OPCODE_STANDARD_QUERY    (0)
...
#define RECURSION_DESIRED_FLAG   (1<<8)
...

uint16_t twoByteBuffer;
...
	twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
...

And ...\Ethernet\src\utility/w5100.h which is included in ...\Ethernet\src\Dns.cpp contains the definition of htons:

#define htons(x) ( (((x)<<8)&0xFF00) | (((x)>>8)&0xFF) )

htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG)=htons(0|0|256) which really gets an overflow for a 16bit integer.

But I have a curious effect:
With Arduino 1.8.15 IDE installed on a Win10-32bit-PC I get the same warning.
But with Arduino 1.8.15 IDE installed on a Win10-64bit-PC there is no warning with the same sketch.

Can somebody explain this?

the version of IDE doesn't matter. the version of toolchain is important. it is bundled with the boards support package (BSP), but some BSPs share the toolchain. for example installing megaavr BSP updates the AVR toolchain for the AVR BSP

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.