The implementation scheme of Ethernet interface based on ENC28J60 is designed, and the design method of hardware architecture of the system is described. Based on the brief introduction of the structure, function and peripheral circuit of Ethernet controller ENC28J60, the SPI communication between ENC28J60 and ATmega16 is described. This scheme not only has low cost, but also can realize the transmission rate above 500kbps, which meets the Internet control requirements of embedded system.
Application of ENC28J60 in embedded network interface
The network terminal nodes with different functions can be constructed by using ENC28J60, such as network server, equipment with internet function, remote monitoring (data acquisition, diagnosis) equipment, etc. Figure 2 shows the hardware circuit diagram of embedded network interface based on ENC28J60. There are two LED status indicators in the circuit, which are mainly used to display the network connection status, including PHY conflict, connection establishment, data reception, connection speed, duplex mode, etc; Necessary bias resistance R3 (2k Ω， The accuracy is 1%); In the application of high-speed LAN electromagnetic isolation module (RJ45 Ethernet interface), when the physical port of ENC28J60 is connected with isolation transformer hr901170a, it must meet the requirements of IEEE802.3 for physical layer specification. For example, the spacing between RJ45 Jack and isolation transformer should be as small as possible, and the wiring of output and input differential signal pairs should be well isolated.
The main controller of the circuit adopts ATmega16 single chip microcomputer of ATMEL company. It has advanced RISC (reduced instruction set computer) structure, 16 KB programmable flash memory, 512 B EEPROM and 1 KB on-chip SRAM. It has rich peripheral interfaces. Its SPI interface allows ATmega16 to carry out high-speed synchronous data transmission with peripheral devices. In this design, ATmega16 SPI is configured as host mode and ENC28J60 as slave device. The SPI working mode of ATmega16 is set by cpol and CPHA. According to the SPI reading and writing sequence of ENC28J60, the SPI working mode of ATmega16 should be set to mode 0. ATmega16 can synchronize with ENC28J60 by setting the CS pin of ENC28J60 low. SPI clock is started by the data written to SPI transmit buffer register. The data transmit order on SPI MoSi (pb5) pin is controlled by the dord bit of register SPCR. When set, LSB (the lowest bit) of data is sent first, otherwise MSB (the highest bit) of data is sent first. We choose to send the MSB first, at the same time, the received data is transferred to the receive buffer register, and the CPU performs right alignment to read the received data from the receive buffer. It should be noted that when it is necessary to read multiple data from ENC28J60, even if ENC28J60 does not need the serial output data of ATmega16, it is necessary to write a data to SPI buffer before reading each data to start SPI interface clock. Since there is only one buffer in the transmitting direction and two buffers in the receiving direction of SPI system, the SPI data register can only be written after the shift process is completed; When receiving data, you need to read the current received data by accessing SPI data register before the end of the next byte shift process, otherwise the first data will be lost.