This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Wiznet5100 ethernet shield on nRF52840

Dear Nordic Devzone,

I want to run an Arduino Ethernet Shield with the Wiznet5100 on the nRF52840. I was wondering if there was an easier way to do this then having to rewrite the SPI code by myself.

www.arduino.cc/.../ArduinoEthernetShieldV1

Currently I am using the Keil IAR /uVision to compile my code and can easily compile and run all the examples included. I am just a bit lost on how to use the ethernet shield with the nRF52840.

I thought I would be able to use some Arduino library to easily get it working.

Any help or direction in which to start would be much appreciated.

ToasTer

Parents
  • i connected W5100 shield to nrf52832 sev board. Here is my sources you can try. W5100.rar NRF5x_SPI.c NRF5x_SPI.h mian code:

    #include "NRF5x_SPI.h"
    #include "w5100.h"
    #include "socket.h"
    #include "tcpclient.h"
    
    W5100_CFG my_cfg = {
    {0x8A, 0x26, 0xF4, 0x1A, 0xD0, 0x93},		// MAC address
    {192, 168, 1, 3},						// IP address
    {255, 255, 255, 0},							// Subnet mask
    {192, 168, 1, 1},							// Gateway
    
    {192, 168, 1, 127},// Dest iP
    SOCKET_PORT // Dest port};
    
    extern uint8_t destip[4];
    extern uint16_t destport;
    extern uint8_t data_buf_rx[255];
    extern uint8_t data_buf_tx[255];
    uint8_t ip[4];
    uint8_t sn[4];
    uint8_t gw[4];
    uint8_t mac[6];
    uint8_t mode = 1; //0 - DHCP, 1 - no DHCP
    uint8_t my_socket = 0;
    uint8_t err;
    uint8_t tcpdata[] = {0x01, 0x02, 0x03, 0x0A, 0x6B, 0x0C};
    uint8_t counter = 0; 
    
    int main(void)
    {
    ....
    SPI_Init();
    ethernet_config();
        ...
    }
    
    void ethernet_config(void)
    {
    Serial_Print((uint8_t*)"\r\nConfig static IP mode...\r\n");
    
    iinchip_init();
    nrf_delay_ms(1000);
    sysinit(1, 1);
    nrf_delay_ms(1000);
    
    setSIPR(my_cfg.ip_addr);
    setGAR( my_cfg.gtw_addr);
    setSUBR(my_cfg.sub_mask);
    setSHAR(my_cfg.mac_addr);
    nrf_delay_ms(100);
    
    getSIPR(ip);
    getSUBR(sn);
    getGAR(gw);
    getSHAR(mac);
    
    memcpy(destip, my_cfg.remip, 4);
    destport = my_cfg.remport;
    
    sprintf(debug_str, "\r\nMY IP: %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
    Serial_Print((uint8_t*)debug_str);
    
    sprintf(debug_str, "SUB NET: %d.%d.%d.%d\r\n", sn[0], sn[1], sn[2], sn[3]);
    Serial_Print((uint8_t*)debug_str);
    
    sprintf(debug_str, "GW: %d.%d.%d.%d\r\n", gw[0], gw[1], gw[2], gw[3]);
    Serial_Print((uint8_t*)debug_str);
    
    sprintf(debug_str, "MAC: %2X:%2X:%2X:%2X:%2X:%2X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    Serial_Print((uint8_t*)debug_str);	
    
    Serial_Print((uint8_t*)"\r\nW5100 configured!\r\n");
    

    }

Reply
  • i connected W5100 shield to nrf52832 sev board. Here is my sources you can try. W5100.rar NRF5x_SPI.c NRF5x_SPI.h mian code:

    #include "NRF5x_SPI.h"
    #include "w5100.h"
    #include "socket.h"
    #include "tcpclient.h"
    
    W5100_CFG my_cfg = {
    {0x8A, 0x26, 0xF4, 0x1A, 0xD0, 0x93},		// MAC address
    {192, 168, 1, 3},						// IP address
    {255, 255, 255, 0},							// Subnet mask
    {192, 168, 1, 1},							// Gateway
    
    {192, 168, 1, 127},// Dest iP
    SOCKET_PORT // Dest port};
    
    extern uint8_t destip[4];
    extern uint16_t destport;
    extern uint8_t data_buf_rx[255];
    extern uint8_t data_buf_tx[255];
    uint8_t ip[4];
    uint8_t sn[4];
    uint8_t gw[4];
    uint8_t mac[6];
    uint8_t mode = 1; //0 - DHCP, 1 - no DHCP
    uint8_t my_socket = 0;
    uint8_t err;
    uint8_t tcpdata[] = {0x01, 0x02, 0x03, 0x0A, 0x6B, 0x0C};
    uint8_t counter = 0; 
    
    int main(void)
    {
    ....
    SPI_Init();
    ethernet_config();
        ...
    }
    
    void ethernet_config(void)
    {
    Serial_Print((uint8_t*)"\r\nConfig static IP mode...\r\n");
    
    iinchip_init();
    nrf_delay_ms(1000);
    sysinit(1, 1);
    nrf_delay_ms(1000);
    
    setSIPR(my_cfg.ip_addr);
    setGAR( my_cfg.gtw_addr);
    setSUBR(my_cfg.sub_mask);
    setSHAR(my_cfg.mac_addr);
    nrf_delay_ms(100);
    
    getSIPR(ip);
    getSUBR(sn);
    getGAR(gw);
    getSHAR(mac);
    
    memcpy(destip, my_cfg.remip, 4);
    destport = my_cfg.remport;
    
    sprintf(debug_str, "\r\nMY IP: %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
    Serial_Print((uint8_t*)debug_str);
    
    sprintf(debug_str, "SUB NET: %d.%d.%d.%d\r\n", sn[0], sn[1], sn[2], sn[3]);
    Serial_Print((uint8_t*)debug_str);
    
    sprintf(debug_str, "GW: %d.%d.%d.%d\r\n", gw[0], gw[1], gw[2], gw[3]);
    Serial_Print((uint8_t*)debug_str);
    
    sprintf(debug_str, "MAC: %2X:%2X:%2X:%2X:%2X:%2X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    Serial_Print((uint8_t*)debug_str);	
    
    Serial_Print((uint8_t*)"\r\nW5100 configured!\r\n");
    

    }

Children
  • Hey thanks for the response, I have been working on this the last few weeks. Got DHCP and DNS working, and got the application layer (HTTP post&get) working last week.

    One thing I noticed with that when using socket 3, I can't send and receive data correctly. Have you had any problems with this?

    Thanks for any response, will take a look at your code.

    ToasTer

  • DHCP was simplified by example i found in web, but it works incorrect. It needs to rewrite with using timer to Discover DHCP packets. Ping doesnt work now too. Now it works wiyh static IP only. IN Socket.c i rewrite some unimportant places, but it does not matter. In general, you only need next files: socket, w5100, tcpclient. They do not affect the code.You need only redefine SPI pins in NRF5x_SPI and rows in structure with ip, sn, gw in main.c. Here is example of using tcp client:

        if(tcpclient_open(s, ip, port))
    {
    	return true;
    }
    else
    {
    	return false;
    }
    
        if(tcpclient_sendbytes(s, packet, length))
    {
    	....		
    }
    else{
               ....
    }
    
        if(tcpclient_recivedata(s, data_buf_rx, data_buf_len))
    {
                 ...
    }
    else
    {
                ...
    }
    
Related