How to Interface SPI-Ethernet with AVR Slicker

Interfacing SPI-Ethernet with AVR Slicker

Tags: Interfacing microchip’s ENC28J60 embedded Ethernet controller with AVR, interfacing Ethernet with AVR Atmega8/16, Circuit Diagram to Interface ENC28J60 with AVR Microcontrollers,
Overall rating
AVR Slicker Board

The AVR Slicker board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports In-system programming (ISP) which is done through Parallel/Printer port.

ATMEL’s AVR (Atmega8535), AVR Slicker Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.

SPI (Serial Peripheral Interface)

Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers.


Ethernet is the most widely-installed local area network (LAN) technology. An Ethernet LAN typically uses coaxial cable or special grades of twisted pair wires. Ethernet is also used in wireless LANs. The most commonly installed Ethernet systems are called 10BASE-T and provide transmission speeds up to 10 Mbps. Devices are connected to the cable and compete for access using a Carrier Sense Multiple Access with Collision Detection (CSMA/CD) protocol.

The ENC28J60 Ethernet Controller

Microchip’s ENC28J60 controller is a 28-pin, 10BASE-T standalone Ethernet Controller, with on board MAC & PHY, 8 Kbytes of Buffer RAM and an SPI serial interface used as an Ethernet network interface for any microcontroller equipped with SPI interface. So the microcontroller can then control remotely any hardware.

Interfacing SPI-Ethernet

Fig. 1 shows how to interface the SPI-Ethernet to microcontroller. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Typically there are three lines common to all the devices,

  • Master In Slave Out (MISO) - The Slave line for sending data to the master,
  • Master Out Slave In (MOSI) - The Master line for sending data to the peripherals,
  • Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by the master, and
  • Slave Select pin - the pin on each device that the master can use to enable and disable specific devices. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master.

This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.


Fig. 1 Interfacing SPI-Ethernet to Microcontroller

The Ethernet buffer contains transmit and receive memory used by the Ethernet controller. The entire buffer is 8 Kbytes, divided into separate receive and transmit buffer spaces. The sizes and locations of transmit and receive memory are fully programmable by the host controller using the SPI interface. Any space within the 8- Kbyte memory, which is not programmed as part of the receive FIFO buffer, is considered to be the transmit buffer.

Interfacing SPI-Ethernet with AVR

In SPI, the clock signal is controlled by the master device AVR Slicker Board. All data is clocked in and out using this pin. These lines need to be connected to the relevant pins on the AVR Slicker Board. Any unused GIO pin can be used for CS, instead pull this pin high. The ENC28J60 requires a single per packet control byte to precede the packet for transmission to Microcontroller. An IP address is used to access the Ethernet control. The ENC28J60 SPI connections with AVR have four I/O lines required.

Pin Assignment with AVR Slicker






Connect PORTB with J20 (ETHERNET)

Turn ON AD0, AD1 and AVCC pin

of CONFIG-II switch SW23

Connect a LAN cable with U16 LAN connector (Straight). The other end of LAN cable should be in a LAN switch


Connect PORTC with LED section (J8)

Connect PORTD with Digital INPUT Section (J7)

Source code is not yet

provided but we can

test this code with

MikroC AVR.




















Circuit Diagram to Interface SPI-Ethernet with AVR


Source Code

The Interfacing UART with AVR program is very simple and straight forward, which controls the LED & Switches in AVR Slicker Board from Ethernet through SPI. In C programs are written in MikroC Compiler software. When we select LED or Switch in Internet Explorer by using IP address then the output is enabled in AVR controller.

C Program to interface Ethernet with AVR


Title : Program to control LED & Switches from Ethernet using SPI



#include  "__EthEnc28j60.h"


void    main()



        // set PORTC as input

        DDRC = 0;

        // set PORTD as output

        DDRD = 0xFF;



         * starts ENC28J60 with :

         * reset bit on PB4

         * CS bit on PB5

         * my MAC & IP address

         * full duplex



        SPI_Ethernet_Init(myMacAddr, myIpAddr, Spi_Ethernet_FULLDUPLEX) ;


        // dhcp will not be used here, so use preconfigured  


        //SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr)        



        while(1) // do forever



                 * if necessary, test the return value to get  

                 error code


                SPI_Ethernet_doPacket() ;  

// process incoming Ethernet packets



                 * add your stuff here if needed

            * Spi_Ethernet_doPacket() must be called as                      

           often as possible

                 * otherwise packets could be lost





To compile the above C code you need the MikroC for AVR software. The software has it’s own IDE and built-in AVR gcc- Compiler. They must be properly installed and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In MikroC for AVR software, you can develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without microcontroller Board.

The MikroC for AVR software is used to download the hex file into your microcontroller through Parallel port.

Testing the SPI-Ethernet with AVR Slicker

Give +12V power supply to AVR Slicker Board; the SPI-Ethernet is connected with AVR Slicker Board. Connect your board to a hub with a straight cable. LEDA should now turn on with LEDB still blinking. LEDA ON means that the adapter is correctly linked to the network. The network link LED of the other side hub should also turn on.

Open the Internet Explorer window and give the IP address. If the entire connections are connected correctly, then the IP address display the LED, switch levels.

Now you can control the input & output port lines (LED & switch) of AVR Slicker Board from Internet Explorer through SPI - Ethernet. If you are not reading any output from LED, then you just check the jumper connections & check the LED is working.

If you are not controlled the I/O port lines of AVR Slicker Board from Internet Explorer, then you just check the IP address & Ethernet connections. Otherwise you just check the code with debugging mode in MikroC for AVR Software.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • The straight cable only used between AVR Slicker Board hub & the network cable hub.
  • Don't plug the ENC28J60 in its socket, then power to the board and verify the 3.3V power supply on each pin of the ENC.
  • More instructions are available in following articles,
       -  User Manual of AVR Slicker Board.
       -  Tutorial of how to create & Debug a project in MikroC for AVR.

Join the World's Largest Technical Community

we respect your privacy.