7 years, 2 months ago.

FRDM-K64F network not working

I have a NXP FRDM-K64F board and I want to set the ethernet example but I cannot get it working. This is how my code looks like after setting the static IP address.

  1. include "mbed.h"
  2. include "main-hw.h"
  3. include "EthernetInterface.h"

Network interface EthernetInterface net;

int main(void) { Bring up the ethernet interface printf("Ethernet socket example\r\n");

int ret; ret = net.set_network("192.168.15.177","255.255.255.0","192.168.15.1"); printf("Set Net: %d\r\n",ret);

char macadd[6]; mbed_mac_address(macadd); printf("%02x:%02x:%02x:%02x:%02x:%02x \r\n", macadd[0], macadd[1], macadd[2], macadd[3], macadd[4], macadd[5]);

const char *mac = net.get_mac_address(); printf("MAC address is: %s\r\n", mac ? mac : "No MAC");

const char *ip = net.get_ip_address(); printf("IP address is: %s\r\n", ip ? ip : "No IP");

ret = net.connect(); printf("Connect: %d\n",ret);

Show the network address const char *ip = net.get_ip_address(); printf("IP address is: %s\n", ip ? ip : "No IP");

Open a socket on the network interface, and create a TCP connection to mbed.org TCPSocket socket; socket.open(&net); socket.connect("developer.mbed.org", 80);

Send a simple http request char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n"; int scount = socket.send(sbuffer, sizeof sbuffer); printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);

Recieve a simple http response and print out the response line char rbuffer[64]; int rcount = socket.recv(rbuffer, sizeof rbuffer); printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);

Close the socket to return its memory and bring down the network interface socket.close();

Bring down the ethernet interface net.disconnect(); printf("Done\n");

return 0; } What I see is that I only get the macAddress with the mbed_mac_address command. With net.get_mac_address and net.get_ip_address I only get NULL values.

The process get to the net.connect and I see no more results.

What am I doing wrong?

I tried to post this same question to the forum but I have not seen it published, so I am not sure if it is duplicated. Sorry If I did it twice.

posted by Jordi Blasi 13 Feb 2017
Be the first to answer this question.