10 years, 5 months ago.  This question has been closed. Reason: Problem Solved - Incorrect Wiring

Ethernet not working - no ip address (new stack)

Hi, I'm trying to get my mbed LPC1768 to communicate via ethernet, but can't get it to work.

I have wired up a MagiJack (SI-60008-F) as per the RJ45 page, I'm assuming it's the same as the top one as it has no LEDs but my part number is slightly different. The TD+/-, RD+/- are connected to the relevant mbed pins, RDC and TDC to 3.3V with a 100n cap to ground, and ground to, well, ground.

I'm trying to run the example code TCPSocket_HelloWorld - main.cpp here. I've plugged the mbed into the back of my router (a Sky hub if that matters) with a tiny 0.5m cat 5e cable, and the orange and green LED on the router port light up and flash a bit. So some communication is happening I think, but the printf from the mbed over serial just returns a blank IP address and then nothing afterwards!

"IP Address is "

Then nothing.

I don't really know what to do/try next, I can't do anything else if DHCP won't assign an IP to the mbed. It shows up in the router logs as "eth3 link UP 100 mbps full duplex" or similar, but not in the router's table of connected devices. It's not a very hackable router so I can't seem to find out any more detailed info from it :/ What would the mbed even show up as name-wise? The code doesn't assign any sort of device name to the mbed unless there is a default one configured behind the scenes...

Any ideas?

Thanks in advance!

Oh and I've tried manually assigning a static IP in the code, which will then show up in the printf, but it still won't do anything after that. I'm guessing the router isn't going to like a device demanding a specific IP. It will want to assign one to it with DHCP. I can't ping it or anything using this static IP anyway, so I don't think it's actually properly registered or working.

posted by Jamie McKee 17 Dec 2013

As requested, more details!

They say a picture is worth a thousand words, so here's a photo of my wiring:

http://i994.photobucket.com/albums/af63/jamiemckee1/Electronics/DSC_0612_zpsadcadcb3.jpg

Ignore the resistor, LED, and mosfet, they were just me messing around.

The wiring is exactly as described here, reproduced below for convenience:

            |   |   |   |         
          --||--||--||--||-----   Socket mbed
        /  8 | 6 | 4 | 2 |    /|       1 TD+
       /    7   5   3   1    / |       2 3.3V
      /                     /  |       3 TD-
     /    Bel Stewart      /   |       4 RD+
    /      MagJack        /    |       5 3.3V
   /     SI-60002-F      /     |       6 RD-
  /___________________  /      |       7 N.C.                                                      
 |      --------       |       |       8 GND                                                      
 |    --        --     |       |                                                               
 | --- |          ---- |      /                                                                
 ||    /--/-/-/-/-/-/-||     /                                 ___                   ________   
 ||   /  8 7 6 5 4 3 2||    /              ________________  -/   \-        ____    |   ____ |  
 ||  /  / / / / / / / ||   /      ,= ,++, /,  ,  ,  ,  ,  ,\|,  ,  ,| ,  , /,  ,| , |,  ,  ,_|  
 || /  / / / / / / / /||  /      ============================================================  
 ||/  ' ' ' ' ' ' ' ' || /        |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |    
 | ------------------- |/         |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |    
  ---------------------                                               ^  ^  ^  ^                
  Ethernet Socket Front           mbed Board                         TD+TD-RD+RD-          

The only difference is that my jack is a SI-60008-F not a SI-60002-F, but it has no LEDs either so I'm hoping it's the same?

I was running the example hello world program

Import program

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 
00004 int main() {
00005     EthernetInterface eth;
00006     eth.init(); //Use DHCP
00007     eth.connect();
00008     printf("IP Address is %s\n", eth.getIPAddress());
00009     
00010     TCPSocketConnection sock;
00011     sock.connect("mbed.org", 80);
00012     
00013     char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
00014     sock.send_all(http_cmd, sizeof(http_cmd)-1);
00015     
00016     char buffer[300];
00017     int ret;
00018     while (true) {
00019         ret = sock.receive(buffer, sizeof(buffer)-1);
00020         if (ret <= 0)
00021             break;
00022         buffer[ret] = '\0';
00023         printf("Received %d chars from server:\n%s\n", ret, buffer);
00024     }
00025       
00026     sock.close();
00027     
00028     eth.disconnect();
00029     
00030     while(1) {}
00031 }

But I've since modified that a bit to try and get a bit more information about what's going on:

posted by Jamie McKee 18 Dec 2013

#include "mbed.h"
#include "rtos.h"
#include "EthernetInterface.h"

int main()
{
    EthernetInterface eth;
    TCPSocketConnection sock;
    int error;
    int retrys = 5;
    
    printf("\r\n");   
    printf("Initialising ethernet...\r\n");
    
    while (true)
    {
        error = eth.init(); //Use DHCP
        //error = eth.init("192.168.0.100", "255.255.255.0", "192.168.0.1"); // Use static IP
        if (error) {
            printf("Error: Could not initialise ethernet (code %i) - Retry (%d)...\r\n", error, retrys);
            Thread::wait(5000);
            retrys--;
            if (retrys)
                continue;
            else
                while(true);
        }
        break;
    }
    
    printf("MAC Address is %s\r\n", eth.getMACAddress());
    printf("Obtaining IP address...\r\n");
    retrys = 5;
    
    while (true)
    {
        error = eth.connect(30000);
        if (error) {
            printf("Error: Could not obtain IP address (code %i) - Retry (%d)...\r\n", error, retrys);
            retrys--;
            if (retrys)
                continue;
            else
                while(true);
        }
        break;
    }
    
    printf("IP Address is %s\r\n", eth.getIPAddress());
    printf("Network Mask is %s\r\n", eth.getNetworkMask());
    printf("Default Gateway is %s\r\n", eth.getGateway());  
    printf("Connecting...\r\n");
    retrys = 5;
    
    while (true)
    {
        error = sock.connect("mbed.org", 80);
        if (error) {
            printf("Error: Could not connect to mbed.org (code %i). Retry (%d) in 5s...", error, retrys);
            Thread::wait(5000);
            retrys--;
            if (retrys)
                continue;
            else
                while(true);
        }
        break;
    }
    
    printf("Connected!\r\n");
    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
    retrys = 5;
    
    while (true)
    {
        error = sock.send_all(http_cmd, sizeof(http_cmd)-1);
        if (error < 1) {
            printf("Error: Could not send http request (code %i) - Retry (%d) in 5s...\r\n", error, retrys);
            Thread::wait(5000);
            retrys--;
            if (retrys)
                continue;
            else
                break;
        }
        char buffer[300];
        int ret;
        while (true)
        {
            ret = sock.receive(buffer, sizeof(buffer)-1);
            if (ret <= 0)
                break;
            buffer[ret] = '\0';
            printf("Received %d chars from server:\r\n%s\r\n", ret, buffer);
        }
        break;
    }
      
    sock.close();
    eth.disconnect();
    
    while (1)
    {
    }
}

Getting an IP address fails with code -1 :/

I'm stumped!

posted by Jamie McKee 18 Dec 2013

2 Answers

10 years, 5 months ago.

I haven't worked with ethernet myself, so I probably can't help too much.

However the 60008 is definately not the same as the 60002. This is the 60002: http://www.farnell.com/datasheets/17297.pdf, and this the 60008: http://www.farnell.com/datasheets/302465.pdf.

Now I believe I read here once for very short distances it might be fine without the aditional stuff, but it is definately not just a different version of the same component.

Accepted Answer

Ah, so what have I got then? Is it just a straight through jack? I looked at the datasheet for mine, saw the transformer looking things and just assumed that was what 'integrated magnetics' was, but apparently not. I've never worked with ethernet before, had no idea it was this complicated!

So do I want to be using the second one down then on the ethernet page? This one:

            |   |   |   |         
          --||--||--||--||-----   Socket mbed
        /  8 | 6 | 4 | 2 |    /|       1 TD+
       /    7   5   3   1    / |       2 TD-
      /                     /  |       3 RD+
     /                     /   |       4 
    /                     /    |       5
   /                     /     |       6 RD-
  /___________________  /      |       7                                                       
 |      --------       |       |       8                                                       
 |    --        --     |       |                                                               
 | --- |          ---- |      /                                                                
 ||    /--/-/-/-/-/-/-||     /                                 ___                   ________   
 ||   /  8 7 6 5 4 3 2||    /              ________________  -/   \-        ____    |   ____ |  
 ||  /  / / / / / / / ||   /      ,= ,++, /,  ,  ,  ,  ,  ,\|,  ,  ,| ,  , /,  ,| , |,  ,  ,_|  
 || /  / / / / / / / /||  /      ============================================================  
 ||/  ' ' ' ' ' ' ' ' || /        |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |    
 | ------------------- |/         |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |    
  ---------------------                                               ^  ^  ^  ^                
  Ethernet Socket Front           mbed Board                         TD+TD-RD+RD-               
posted by Jamie McKee 18 Dec 2013

I have no idea :P. As I said I haven't used ethernet myself, just checked those two components. Hopefully someone else can give more info.

posted by Erik - 18 Dec 2013

Well I changed the wiring to the above and it worked! Hooray! I feel rather silly now, haha. I thought my wiring was correct because I saw lights and some signals moving about.

I'll mark your answer as correct as it's what lead me to the solution, thanks for your help! :)

posted by Jamie McKee 18 Dec 2013
10 years, 5 months ago.

HI Jamie, can you post your code(use <<code>> and <</code>> tags for better understanding) and schematics to try to help you? and tell me what connector are you using exactly?

Greetings

Question updated! :)

posted by Jamie McKee 18 Dec 2013