Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to define a IP address for microcontroller board ?

Status
Not open for further replies.

neduva

Junior Member level 3
Joined
May 29, 2012
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,451
hello friends,

can we define IP address for simple microcontroller board.
 

Are you asking for the PC side settings to assign a static network IP to a device?
Which OS do you use?
 

ya. i'm asking about the board with simple sensors interfaced to microcontroller.
can we set IP for that board. for remote access through pc.
 

ya. i'm asking about the board with simple sensors interfaced to microcontroller.
can we set IP for that board. for remote access through pc.
if you are managing IP addresses yourself, e.g. a small local network in a factory, you can assign static IP addresses to each board, e.g.
1. in the code - but you have to edit and rebuild the code for each new board
2. in EEPROM set up when you initialize the board for the first time

e.g. some code from a PIC18 using function from Microchips "TCPIP Stack/TCPIP.h"
Code:
// set up TCP/IP stack and open sockets to send and receive UDP datagrams
int openUDPsockets(void)
{
  StringToIPAddress(eeprom.IPaddress,&AppConfig.MyIPAddr);
  DisplayIPValueROM("My IP address ",  AppConfig.MyIPAddr);
  // for some reason we have to cast these parameters to (int)
  GLCDprintf(3, "My IP: %d.%u.%u.%u", (int) AppConfig.MyIPAddr.v[0], (int) AppConfig.MyIPAddr.v[1], (int) AppConfig.MyIPAddr.v[2], (int) AppConfig.MyIPAddr.v[3]);
  AppConfig.DefaultIPAddr.Val = AppConfig.MyIPAddr.Val;

  ROMStringToIPAddress((ROM BYTE*) DEFAULT_IP_MASK,   &AppConfig.MyMask);

if connected to a network with a DHCP server let it assign an IP address (if your microcontroller runs a server it will probably need a static IP address)

a more difficult problem with microcontrollers is setting up the MAC address of ethernet interfaces - these days we tend to use a chip with a MAC address and EEPROM, e.g.
**broken link removed**
 

ya i have an idea to use ethernet port through ENC28j60 ic.
 

ya i have an idea to use ethernet port through ENC28j60 ic.

in a recent project we used a PIC24FJ256GB106 with a ENC28j60 ethernet IC
we adapted Microchip's Microchip Solutions v2012-07-18\TCPIP\Demo App\GenericTCPClient() example code from
**broken link removed**

in a ENC28j60 header file a default IP of 192.168.1.5 is setup
Code:
#define MY_DEFAULT_IP_ADDR_BYTE1        (192ul)
#define MY_DEFAULT_IP_ADDR_BYTE2        (168ul)
#define MY_DEFAULT_IP_ADDR_BYTE3        (1ul)
#define MY_DEFAULT_IP_ADDR_BYTE4        (5ul)

which is then replaced when the DHCP server assigns an IP address
Code:
	// Initialize Stack and application related NV variables into AppConfig.
	InitAppConfig();
    // set our MAC address from the MCP79410 device
        MCP79410readMACaddress((unsigned char *)&AppConfig.MyMACAddr);
    DisplayMACaddress("My MAC address  ",AppConfig.MyMACAddr);
	// Initialize core stack layers (MAC, ARP, TCP, UDP) and application modules (HTTP, SNMP, etc.)
    StackInit();
    printf("Ethernet TCP/IP stack initialised\r\n");
    // main program loop
    mSecElapsed(1,1,0);
    while(1)
    {
        static int connectToHost = 0;
        StackTask();			// do TCPIP stack task
        StackApplications();	// do core stack application tasks

        // has local IP address changed (ex: due to DHCP lease change)
	if(dwLastIP != AppConfig.MyIPAddr.Val)     // new IP address assigned
		{
			dwLastIP = AppConfig.MyIPAddr.Val;
		    DisplayIPValue("\r\nNew IP Address:      ",  AppConfig.MyIPAddr);
		    DisplayIPValue("New gateway Address: ",  AppConfig.MyGateway);
		    DisplayIPValue("New DNS Address:     ",  AppConfig.PrimaryDNSServer);
            DisplayIPValue("Default IP mask      ",  AppConfig.MyMask);
		}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top