User manual

Table Of Contents
482
mikoC PRO for PIC32
MikroElektronika
SPI_Ethernet_24j600_initDHCP
Prototype
unsigned int SPI_Ethernet_24j600_initDHCP(unsigned char tmax);
Description This is DHCP module routine. It sends an DHCP request for network parameters (IP, gateway, DNS
addresses and IP subnet mask) and waits for DHCP reply. If the requested parameters were obtained
successfully, their values are stored into the library global variables.
These parameters can be fetched by using appropriate library IP get routines:
- SPI_Ethernet_24j600_getIpAddress - fetch IP address.
- SPI_Ethernet_24j600_getGwIpAddress - fetch gateway IP address.
- SPI_Ethernet_24j600_getDnsIpAddress - fetch DNS IP address.
- SPI_Ethernet_24j600_getIpMask - fetch IP subnet mask.
UDP port 68 is used as DHCP client port and UDP port 67 is used as DHCP server port.
Parameters - tmax: time in seconds to wait for an reply.
Returns - 1 - network parameters were obtained successfully.
- 0 - otherwise.
Requires Ethernet module has to be initialized. See SPI_Ethernet_24j600_Init.
Example
...
SPI_Ethernet_24j600_initDHCP(5); // get network conguration from DHCP
server, wait 5 sec for the response
...
Notes The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will
be processed normaly during this time.
When DHCP module is used, global library variable SPI_Ethernet_24j600_userTimerSec is
used to keep track of time. It is user responsibility to increment this variable each second in it’s code.