Network card configuration for network communication using microcontroller

Network card configuration for network communication using microcontroller

The key to network communication using a microcontroller is to drive and configure a network interface card, and RTL8019 is REALTEK's highly integrated dedicated Ethernet interface chip, supports PnP automatic detection, and is embedded with 16K SRAM, with a full-duplex communication interface Transmitting and receiving data on the twisted pair through the switch at the same time, increasing the bandwidth from 10 trillion to 20 trillion, is an ideal chip for Ethernet communication.
RTL8019AS is designed for the ISA bus. It is used to realize the physical layer protocol of the network on the PC, mainly including the physical connection of the network card and the network cable, media access control (such as CSMA / CD), disassembly and assembly of data frames, frame transmission Receive, error check, data signal encoding / decoding (such as Manchester code and NRZ code conversion, etc.), data serial, parallel conversion and other functions. To realize these functions, the network interface chip must be correctly configured.
Most microcontrollers are 8-bit, so the interface chip must be set to 8-bit mode when using 8-bit MCU and RTL8019AS interface. The specific code is now used to explain in detail the configuration of RTL8019AS with MCU, so as to realize the use of microcontroller Perform network communication.
The RTL8019 has a total of four page register groups, each page register group has 16 registers. In fact, network communication is to set these registers. Among them CR register is the control command register, the address is 00h, the meaning of each bit is shown in Table 1, this register is used to select the register page and control the remote DMA operation.
PS1, PS0 are used to specify the page of the register. In the actual configuration of the register, you must first specify which page the register to be configured belongs to (that is, set the PS1 and PS0), and then write configuration information to the register on that page.
To perform network communication, the network control chip must be initialized. The initialization is cumbersome, but it is very important. It determines some important parameters of network communication. The detailed configuration process is as follows.
Table 1 The meaning of each bit of CD register

NO NAME TYPE Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
00h CD R / W PSI PS0 RD2 RD1 RD0 TXR STA STP


1. Initialize the reset register, address 1fh, the code is as follows.
mov nicIOAddr, # $ 1F; give the address of the reset register mov w, # 0; write data 0
call NICWrite; transfer subroutine, write data to 2. Select RTL8019as as the user configuration mode, then write enable the 9346CR register, and then set the configuration register 2 of the RTL8019AS, the code is as follows.
clr nicIOAddr; select CR register mov w, # d1h; select the third page, stop the transfer operation call NICWrite; write data mov nicIOAddr, # $ 01; select 9346 CR register mov w, # d0h; configure register write enable call NICWrite; write Input data mov nicIOAddr, # 05h; select configuration register 2
mov w, # 0h; network connection automatic detection enable (10BaseT)
call NICWrite; write data 3. Configure the current page register (select the first page 07h register when writing, and the second page 07h register when reading).
inc nicIOAddr; ($ 07) The CURR register points to the first page of the receive buffer (256 bytes per page)
mov w, #RXBUF_START; write the start address in the CUR register call NICWrite; write data 4. Configure the size of the receive buffer (in the first page register set).
clr nicIOAddr; select the first page register mov w, # 01h; write data 1
call NICWrite; write data inc nicIOAddr; "page start register" ($ 01, PSTART) sets the start page of the receive buffer mov w, #RXBUF_START
call NICWrite; write data inc nicIOAddr; "page termination register" ($ 02, PSTOP) sets the end page of the receive buffer mov w, #RXBUF_END
call NICWrite; write data 5. Set the boundary register inc nicIOAddr; ($ 03) BNRY () is used as a pointer to the received data of the last page in the data buffer mov w, #RXBUF_START
call NICWrite; write data 6. Set the interrupt register (address at 07h on the first page)
mov nicIOAddr, # $ 07; ISR interrupt register mov w, # $ FF
call NICWrite; The meaning of each bit of the write data interrupt register is shown in Table 2.
8. Set the receive configuration register (0C, RCR)
mov nicIOAddr, # $ 0C; RCR is set to throw away the wrong received packets; packets that do not support multicast addresses; receive packets of less than 64 bytes; support broadcast addresses; the physical destination address must be in contact with PARO-5 The addresses match; the data is buffered in memory; the packets with errors are rejected.
mov w, #% 11000110
call NICWrite;
Table 2 The meaning of each bit of the interrupt register

Bit symbol description
7 RDC Set "1" when the NIC starts, set "1" when the start command is written to the CD, and set "0" when the packet is read from the buffer
6 RDC Set to "1" when the remote DMA operation is completed
5 CNT Set "1" when the network calculator is set
4 OVW Set to "1" when the receive buffer is used up
3 Set to "1" when the transmission packet is dropped due to network problems
2 RXE Set to "1" when: CRC check error;
Frame pair error; packet loss
1 PTX This bit indicates that there is no error in sending the packet
0 PRX This bit indicates that there is no error in receiving the packet


9. Set the transmit configuration register (0D, TCR)
inc nicIOAddr; TCR is set to address matching check, CRC check and frame alignment check for the packet; the physical destination address must match the contact address at PARO-5; packets that do not support multicast addresses; send less than 64 words Section of the packet.
mov w, #% 11100000
call NICWrite
10. Set the data configuration register (0E, DCR)
inc nicIOAddr; the data is configured in the lower 8 bits, one byte at a time instead of one word mov w, #% 10111000
call NICWrite; transfer subroutine, write data to 11. Start receiving data clr nicIOAddr; select CR register mov w, #% 00000010; Page0, the data is set to start receiving call NICWrite; write subroutine, write data to the network controller using the microcontroller to set the above settings, and then combine the high-level With TCP / IP protocol, data can be transmitted on Ethernet.
Using the 8-bit microcontroller to configure the register of the network control card is more cumbersome. The above process and code are only a brief introduction. Users can also make some special settings for their special needs. In short, the principle of improving data transmission efficiency is the principle.

TWO FUNCTION : MCB AND RCCB FUNCTIONS

Residual Current Circuit Breaker With Over Load Protection

Residual Current Circuit Breaker,Residual Current Circuit Breaker with Over Load Protection 1p,Residual Current Circuit Breaker with Over Load Protection 2p

Wenzhou Korlen Electric Appliances Co., Ltd. , https://www.korlenelectric.com