How to get the MAC address of a W5500 shield?

This can't be a new question but I have not been able to find an answer. I am using an Arduino Mega with a Seeed Ethernet shield. The shield uses a W5500 chip. I looked through the libraries and found a reference to a getMacAddress function in the 5100.h source file.

gW5100.getMACAddress(mac_address)

I plugged it into my sketch (attached) and it compiled and ran, but all I get as a result are zeroes. (Screen shot, attached).

I looked at the datasheet for the W5500 chip and registers 0x0009 - 0x000E are used to store the MAC address. Does anyone know how I can read those registers?

Thanks,
Mike

Screenshot.jpg

ArduinoEthernet-01.ino (4.29 KB)

You don't read it until you assign it. In your code, this is it.

byte mac[] = { 0x2C, 0xF7, 0xF1, 0x08, 0x00, 0x9A };

// then in setup
  if (Ethernet.begin(mac) == 0)

Thanks.

My understanding was that these types of devices were shipped with MAC addresses already installed, that my defining it replaced it.

If this project works out I may end up making 150 or so per year and having to hard code the MAC address will be a real pain. I could store a value on the SD card, but that still means reading the number off the sticker and typing it in.

Mike

I'm working on this as well. It is strange that the answer is so hard to find.

Are you using this library: GitHub - Wiznet/WIZ_Ethernet_Library: WIZnet Ethernet Library ?

Did you uncomment the line: #define WIZ550io_WITH_MACADDRESS ?

Looking at your code, I would get rid of most of the code except the part that should get and print the mac id. It will make it easier to troubleshoot and for others to help.

In the WebClient example, you see this:

// start the Ethernet connection:
#if defined(WIZ550io_WITH_MACADDRESS)
if (Ethernet.begin() == 0) {
#else
if (Ethernet.begin(mac) == 0) {
#endif

If you uncommented the library properly, the first Ehernet.begin should give you the MAC address. I don't know my board in front of me, but from here, we just need to figure out how to access the variable that holds the mac id. It might be as simple as Serial.print(mac);

I'll give this a try this weekend, but please post back if you find the solution.

I found a thread on the Wiznet wiki that says it is not possible to get the mac address from within the software. You would have to get it from a router, for example.

http://wizwiki.net/forum/viewtopic.php?t=501

Hi guys,

I stumbled into this problem a days ago, and I think I came up with some solution (or so I think).

Before I came up with a solution, I read this thread: WIZ550io schematic and PIC memory for MAC Address - #4 by Edward - WIZ550io - WIZnet Developer Forum

So the conclusion is if you use software reset, the MAC Address value (and the other like IP, DNS, Gateway, etc) on the Common Register W5500 became zero. I peek into the Ethernet library and found out everytime we init the Wiznet module, we do software reset. You can find it on w5500.cpp:

void W5500Class::init(uint8_t ss_pin)
{
  SPI_CS = ss_pin;

  delay(1000);
  initSS();
  SPI.begin();
  w5500.swReset(); //<-- Software reset
  for (int i=0; i<MAX_SOCK_NUM; i++) {
    uint8_t cntl_byte = (0x0C + (i<<5));
    write( 0x1E, cntl_byte, 2); //0x1E - Sn_RXBUF_SIZE
    write( 0x1F, cntl_byte, 2); //0x1F - Sn_TXBUF_SIZE
  }
}

So what I do is comment the //W5500.swReset();, and voila, I can read the MAC Address. Here is the code to read MAC Address in case you need it. Don`t forget to uncomment #define WIZ550io_WITH_MACADDRESS on file Ethernet2.h first.

#include <SPI.h>
#include <Ethernet2.h>

IPAddress ip(192, 168, 202, 133);
EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  Ethernet.begin(ip);
  server.begin();
  byte mac_address[6] ={0,};
  w5500.getMACAddress(mac_address);
  for(int i = 0; i < 6; i++) {
    Serial.write(mac_address[i]);
  }
}

void loop() {
}

But please be aware if your Wiznet module is already flashed by software reset, you need to rewrite the MAC Address using Ethernet.begin(mac) (and it goes without saying, please comment #define WIZ550io_WITH_MACADDRESS on file Ethernet2.h before do Ethernet.begin(mac)).

But this solution came up with anoher question: Why we need to do software reset after all? I have comment it and still haven`t find any problem till today. If you know, please kindly share it here.

Sorry for my bad english. Hope it helps guys.