“The role of computer communication systems, especially the Internet, in daily life is becoming more and more important, and the development trend is accelerating. Nowadays, Internet access is no longer the patent of personal computers and network workstations. Many embedded systems controlled by microcontrollers (or single-chip microcomputers) have also become members of Internet network nodes. Usually, such embedded systems can be called Embedded Internet Terminal.
The role of computer communication systems, especially the Internet, in daily life is becoming more and more important, and the development trend is accelerating. Nowadays, Internet access is no longer the patent of personal computers and network workstations. Many embedded systems controlled by microcontrollers (or single-chip microcomputers) have also become members of Internet network nodes. Usually, such embedded systems can be called Embedded Internet Terminal. Just imagine, if the remote microcontroller can be controlled through a web browser, and the signals collected by the microcontroller can be received, it will bring great convenience to people’s lives and greatly promote the development of productivity. For example, if a computer in the office is connected to the Internet and an embedded controller installed in the home, people can learn about the home or everything that happens, then a series of problems such as home security will be well resolved. .
MSP430 is a 16-bit microprocessor developed by TI (TexasInstruments, Texas Instruments, USA). Its outstanding feature is that it emphasizes low power consumption. It is very suitable for various applications with low power requirements. There are multiple series and models. Because of its high cost performance, it is widely used in many fields such as home automation, medical equipment, security systems, building control systems, etc. The MSP430F149 used in this Internet terminal design scheme is a member of the MSP430F1X added by TI in 2000.
2. Protocol basis
ISO (InternetStandardOrganization, International Standards Organization) proposed OSI (OpenSystemInterconnect, Open System Interconnect) seven-layer network model in 1981. The biggest advantage of the seven-layer network model is to clearly distinguish the three concepts of service, interface and protocol: service describes what functions a layer provides for the upper layer, interface describes how the upper layer uses the services of the lower layer, and protocol Involves how to implement the services of this layer.
The four-layer network model adopted by the Internet is a subset of the OSI seven-layer network model. Its specific four layers are: application layer, transport layer, Internet layer and network layer. Figure 1 shows the four-layer network model of the Internet and the OSI seven-layer network. Correspondence diagram of the model. The Internet model ensures that all transmitted data can be reassembled in the normal order at the remote end through the sequence number in the data segment (Segment), and the integrity of the data transmission is guaranteed by confirmation.
Figure 1: Correspondence between OSI seven-layer protocol and Internet four-layer model
2.1 Ethernet (Ethernet)
Ethernet is the most widely used local area network. It belongs to the network layer in the four-layer network model of the Internet. Each node in the Ethernet network has the same right to access the network, and their occupation of the network is realized by the method of Carrier Sense Multiple Access with Collision Detection (CSMA/CD). The data is encoded in Manchester, and the connection in the network generally adopts twisted pair or coaxial cable. Each node in Ethernet has a 48-bit, uniquely numbered address. The maximum length of each frame of data is 1518 bytes, the first 48 bits are the destination address, the second 48 bits are the data source address, and then the 2-byte data frame type value. At the end of the data frame, the automatic Generates a 4-byte Cyclic Redundancy Check (CRC) value used to ensure the integrity of the data frame.
2.2 Transmission Control Protocol TCP (Transmission Control Protocol)
TCP provides a reliable data stream service, and although TCP is a member of the DARAP protocol group, it has a great deal of independence. It only has the most basic requirements for the underlying network protocols, and it is easy to build on different networks, so it is very popular. The fourth type of TP-4 in the ISO/OSI transport layer standard is based on TCP as a prototype. TCP can work on numerous networks and can provide virtual circuit services and data stream-oriented transport services. User data can be delivered in an orderly and reliable manner. In the case that a packet may be lost, destroyed, repeated, delayed or out of sequence, the TCP service can provide a reliable inter-process communication mechanism, and the protocol can automatically correct various errors.
2.3 Internet Protocol IP (Internet Protocol)
The most important protocol at layer 3 is IP. It links multiple networks into an internetwork. The job of IP is to connect more than one packet-processing network into an Internet. The basic task of IP is to transmit datagrams through the Internet, and each IP datagram is independent of each other. The IP layer on the host provides services to the transport layer based on the services of the data link layer. IP obtains data from the source transport entity and passes it to the IP layer of the destination host through its data link layer services. The gateway passes the next network datagram to the destination host or the next gateway.
2.4 Address Translation Protocol ARP (AddressResolutionProtocol)
In the TCP/IP network environment, the group-bit IP address assigned by each host is only a logical address, so it must be converted into a physical address during transmission, and the ARP protocol completes this function. ARP enables a host to find the physical address of any physical host on the same physical network, simply by giving the host’s internet address. It can be seen that the physical addressing of the basic network is transparent to network layer services.
2.5 Other agreements
Among the Internet network protocols, there are other related protocols, such as: Reverse Address Translation Protocol RARP (ReverseAddressResolutionProtocol), User Datagram Protocol UDP (UserDatagramProtocol), Internet Control Message Protocol ICMP (InternetworkcontrolMessageProtocol), Hypertext Transfer Protocol (hypertexttransferprotocol) ) and so on, what important roles do they have in the data exchange of the Internet, this article is limited in space and will not be introduced in detail.
3. Hardware Design
The two important components used in this design are TI’s microprocessor MSP430F149 and Crystal’s Ethernet controller CS8900A. These two components are briefly introduced below, and then the hardware implementation is discussed.
MSP430F149 has 60K bytes of FLASH memory and 2K bytes of RAM, watchdog timer (WatchdogTimer), 6 8-bit general-purpose I/O ports, 12-bit A/D converter, 2 serial communication interfaces and 1 hardware multiplier etc. The 60K bytes FLASH memory of MSP430F149 is enough to store web page data, 6 general-purpose I/O ports can be used to control the Ethernet controller CS8900A, and can also be used to execute other user commands, 12-bit A/D converter can be used to Collect data at the terminal, and then send it to the user through the network.
CS8900A low-power Ethernet controller is widely used in industrial computers. Its highly integrated design (only few peripheral components are required in the application) and simple and easy bus interface are very suitable for this design. At present, many Ethernet controllers only provide PCI (Peripheral Component Expansion Interface) interface, while CS8900A can be directly connected to microcontroller. Therefore, CS8900A can be directly controlled by I/O port of MSP430F149. The specific connection method is as follows: shown in Figure 2. In addition, CS8900A can be powered by 3V directly, which is conducive to level matching with MSP430F149.
Figure 2: Schematic of the hardware circuit
3.3 Interface between MSP430F149 and CS8900A
CS8900A has three working modes: I/O mode, memory mode and direct memory storage mode. The default is I/O mode, which can be used in other modes through programs. Each working mode of CS8900A has its own advantages and disadvantages. In this design, its I/O mode is adopted. CS8900A has a total of 8 16-bit I/O ports, and these 8 I/O ports correspond to 8 16-bit registers in the chip. As shown in Figure 2, the CS8900A is connected to the P5 port of the MSP430F149 using an 8-bit data bus, and there are 14 pins used in the interface. After reset, CS8900A selects I/O address as 0x300 by default, and keeps working at this default address all the time.
3.4 System hardware principle
The hardware principle of the whole system is shown in Figure 2, and each module in the figure is analyzed in detail below.
The XTAL1(97) pin and XTAL2(98) pin of CS8900A are connected to a 20MHz crystal oscillator. Since the capacitor is integrated at the XTAL on-chip, no external capacitor is required. The reset pin of CS8900A is active high. When the chip is powered on, it needs a reset signal, which is provided by R9 and C17 jointly. The CS8900A has two different LED control pins: the LANLED(100) pin and the LINKLED(99) pin, which are used to control the LEDs to Display the working status of the CS8900A. The LANLED pin is connected to a red LED (D1). When CS8900A receives or sends data, this pin outputs a low level and lights up the red LED. The LINKLED is connected to a yellow LED (D2). When the CS8900A is connected to a working Ethernet network, the yellow LED will light up.
The circuit related to MSP430F149, in addition to the above-mentioned part connected to CS8900A, also has JTAG (JointTestActionGroup) interface, crystal oscillator and reset circuit. Among them, the JTAG interface is used for programming and debugging, and a 14-pin connector is used to lead out four pins of TCK, TDI, TDO/TDI for programming and debugging, which can be directly connected to the debugging tool FET (FLASHEmulationTool) of MSP430. Users can also lead out the serial communication port of MSP430F149 through the level conversion chip MAX3221 to realize the required functions. The MSP430F149 clock circuit part needs to be connected to an 8MHz crystal oscillator and two 15pF capacitors.
The whole system is powered by 3.3V power supply, and the green LED (D4) is the power indicator of the whole system. For the needs of system expansion, all unused I/O pins of MSP430F149 can also be drawn out with connectors.
When designing a PCB (printed circuit board), filter the bypass capacitor to provide a regulated power supply signal to the MSP430F149 and CS8900A. In order to get better system performance and reduce electromagnetic interference, it is best to arrange the PCB as a four-layer board.
3.5 Interface between CS8900A and LAN
CS8900A integrates a 10M Ethernet transceiver on-chip, which integrates all analog and digital circuits for communication with LAN, which can be directly connected to LAN through an electromagnetic isolator E2023. Resistor R1 is used to connect the two receive lines, and resistors R2 and R3 connected to the two transmit lines are used for impedance matching. RJ45 is a network connector, which can be connected to a 10M or 100 network hub.
4. Software Design
The software part of this design is mainly divided into four parts: Ethernet module, TCP/IP module, API (Application Program Interface) and HTTP (Hypertext Transfer Protocol) service module, all programs are written in C language (easy to communicate with other micro-controllers) The extension of the interface of the server system), and compiled by IARWorkbenchforMSP430V2.10.
4.1 Ethernet Module
The main function of the Ethernet part of the program is to drive the Ethernet controller CS8900A, provide other modules with interfaces for reading and writing CS8900A registers in the form of functions, and generate clocks for reading and writing CS8900A. An Ethernet program contains various configurations of network interfaces, and most importantly, the configuration of MAC (Media Access Control) addresses. The MAC address has a total of 48 bits. In the program, 6 unsigned integer variables are used to store the MAC address value. Each MAC address value must be unique and cannot be 0xFFFFFFFFFFFF.
The configuration process of the Ethernet controller is as follows: After the system is powered on, first call the function Init8900() to initialize the Ethernet controller CS8900A, then the CS8900A is reset, and the MSP430F149 sends the local MAC address in the form of a configuration sequence word. To the CS8900A, the CS8900A stores the MAC address in a register. After the configuration is completed, the MSP430F149 can read and write data to the CS8900A.
4.2 TCP/IP module
The TCP/IP module is the key to the entire system software. It defines the protocol for using the network to send and receive data, uses the various read and write functions provided by the Ethernet module to receive or send data, and provides an easy-to-use API interface for the application layer. .
In the TCP/IP module, the most important function is DoNetworkStuff(). The main function of this function is to process TCP events and should be periodically called by the user program. In the function DoNetworkStuff(), some flags used to mark the working state of CS8900A and MSP430F149 are defined. The work flow of this function is shown in Figure 3. The shorter the period when the function DoNetworkStuff() is called, the better the performance of the system executing the TCP/IP protocol.
Figure 3: System Workflow Flowchart
In order to better coordinate the received and sent data, the TCP/IP module is allocated three buffers in the SRAM, TxFrame1, TxFrame2 and RxTCPBuffer. Among them, the main function of TxFrame1 is to provide buffer memory for TCP data frames to be sent (including Ethernet, IP, and TCP frame headers); the main function of TxFrame2 is to provide TCP non-data frames (including Ethernet, IP, and TCP frame headers) Provide buffer memory for ARP and CIMP protocol frames; RxTCPBuffer provides buffer memory for received TCP data. The larger the buffer allocated, the faster the transmission and reception, as this reduces the lag caused by insufficient buffers.
A network communication connection can be established by calling the function TCPPassiveOpen() or TCPACtiveOpen() in an active or passive manner. The function of the function TCPPassiveOpen() is mainly to send the data packet into the buffer when it detects that there is a data packet sent in. The main function of the function TCPACtiveOpen() is to send the data packet to be sent into the buffer. Before actively sending a data packet, first set the MAC address to receive the data packet, and include the local address into the data packet. Once the connection is established, data can be sent, and the status of the connection can be read out through the corresponding interface function. When the data is sent, the connection can be closed through the function TCPClose().
In the process of sending and receiving data packets, different tasks require different processing time. This time can be provided by the timer Timer_A of MSP430F149, but it must be noted that before using the timer Timer_A, it must be initialized, which is the same as using Other microcontrollers are similar. In order to reduce the error caused by unsuccessful data packet transmission, when the receiver receives the data, it should return a correct received signal. When the transmitter exceeds the set time and still cannot receive the correct received signal, the TCP/IP module automatically Carry out data packet retransmission, this process can be realized through corresponding variables and functions.
Although each company’s software has different procedures for processing the TCP/IP protocol, fortunately, the compatibility of each company on the TCP/IP protocol is very good. Therefore, as long as the user writes programs according to the TCP/IP protocol, Communication between different programs should not be a big problem.
4.3 API (Application Programming Interface)
In order to enable users not only to use current applications, but also to build embedded applications suitable for their own requirements, API functions should be reserved during the entire software compilation process, so that users do not need to know too much about the TCP/IP protocol. The secondary development can be carried out on the basis of the original program. The software fully considers this point, leaving many AIP functions for users, the main ones are TCPClose(), TCPReleaseRxBuffer() and TCPTransmitTxBuffer(). Among them, the main purpose of the function TCPClose() is to close the opened connection. Before closing the connection, the sent data packet remains in the sending buffer to ensure correct transmission. After the connection is closed, if the user wants to re-establish the connection, The IP must be reset, the I/O ports reassigned and the connection re-established. The main function of TCPReleaseRxBuffer() is to call this function after reading the data in the buffer, without saving the correctly read data packets, so that the buffer can be freed for storing new data packets. The user can use the function TCPTransmitTxBuffer() to send data through the established connection, but before using this function, the user should check the SOCK_TX_BUF_RELEASED flag to determine whether there is an available send buffer. In this design, variables (flags) for checking the connection state and sending and receiving state are also provided, such as SOK_ACTIVE, SOCK_CONNEDTED, etc.
4.4 HTTP Application
After doing the above work, the user can establish an HTTP server, and realize the communication between different microcontrollers or workstations through the TCP/IP protocol. HTML (Hypertext Link Markup Language) web page data can be stored in the on-chip FLASH memory of the MSP430F149. Web pages can finish receiving data, sending web data, closing connections, and waiting for other applications to connect. In addition, the web page created by the user can dynamically update the data in real time. Of course, whether to run an HTML web page application program on a common computer or a microcontroller, to communicate with other computers, a single, valid MAC address must be set as described above.
With the development of network technology, there are more and more miniature embedded Internet terminals that need network connection and communication, which can be applied not only in daily life, but also in many industrial sites, especially in those scattered, shared data or The technical superiority of embedded network terminals in industrial fields that need to share certain information is even more evident. In addition, the power consumption of MSP430 series microcontroller is very low, which solves the power supply problem in some special occasions very well. It can be seen that the design scheme discussed in this paper has great application prospects.