Implementation of a DHCP client using AVR and W5100

In this article, we will take a look at an implementation of DHCP using Wiznet’s W5100 chip. The code is available for download. The TCP/IP stack is hardwired in the W5100 chip. We will only implement an incomplete version of DHCP. It will make the code relatively short so that it won’t be heavy on the microcontroller’s memory. It also keeps the code simpler and easier to understand. It is sufficient for most hobbyist and student projects.

Wiznet provides a library for implementing DHCP. ┬áSome code has been taken from the library for our purpose. The code runs upon another library (called the driver) provided by Wiznet. It provides a BSD standard access to the W5100’s TCP/IP stack. The driver first needs to be configured for your particular microcontroller. It is assumed that you have already done that.

Detailed information about DHCP (Dynamic Host Configuration Protocol) is available in RFC 2131 and RFC 2132.

The code has been written for Atmel’s ATmega16 AVR microcontroller. The functionality has been implemented in a single function which is meant to be called only once during the program. It returns 1 on success and 0 on failure.

The working of the program is explained in the following flowchart:

Flowchart for incomplete DHCP client program

Flowchart for the DHCP client program

The code is available for download in two files. The file dhcp.h contains macro definitions and declarations. The file dhcp.c contains the definition of our function.

Click here to download the code


Cooperative Market, Karachi

For college students and hobbyists who love to play with electronics, the most popular place to get themselves armed is the Cooperative Market. Located in Saddar (one of the oldest parts of Karachi), this place can provide everything from discrete components to ready made systems. The market also provides services such as PCB etching and soldering. Finding the right shops can be a bit of a problem for starters.

It is quite possible that you won’t be able to get exactly what you want (unless it’s a large order) and you’ll have to make compromises regarding the components. In case you are looking for specialized boards or programmers, it is a good idea to search the web.

The market is close to Bandar Road (officially M.A. Jinnah Road) which ends at the Karachi Port or “Bandar Gah.” It is right next to St. Andrew’s Church (or the Scottish Church.)

As with the rest of t he Saddar area, traffic jams are common. Saddar area is in a great need of a good Mass Transportation System.