Specifications

SLAA137A
MSP430 Internet Connectivity 21
4.3.1 Functions
void TCPLowLevelInit(void)
This function does a basic setup of the ethernet controller and numerous variables; it also
configures ports and timer_A of MSP430. It must be called before any data transmission via
TCP/IP can take place.
void TCPPassiveOpen(void)
By calling this function, the stack switches to the server mode to detect an incoming connection.
The flag SOCK_ACTIVE is set indicating the stack is busy now. Before calling this function, the
local TCP port must have been configured. The local IP address is specified by a constant
declaration in the header file tcpip.h. The following example shows how to open a connection.
TCPLocalPort = 80; // port of a HTTP-server
TCPPassiveOpen(); // listen for any incoming connection
(…)
If a client successfully establishes a connection to the server, the SOCK_CONNECTED flag in
the register SocketStatus is set.
void TCPActiveOpen(void)
This procedure tries to establish a connection to a remote TCP server. The flag SOCK_ACTIVE
is set and an ARP request to find out the MAC address of the other TCP will be sent out. If the
destination IP address does not belong to the actual subnet, the IP address of the gateway is
used for the ARP request instead. The IP addresses as well as the local and remote TCP port
must be set up before doing an active open. After the opening of the connection, the
synchronization of the TCPs, and the state change of the local TCP to ESTABLISHED, the
SOCK_CONNECTED flag is set and data transfer can take place by using the appropriate API
functions. If an error occurs while opening the connection (for example, destination host is
unreachable), the connection is reset and an error code is stored into the SocketStatus variable
accordingly.
The following example shows how to perform an active open. If the module is connected to a
router and the gateway IP is configured properly, you should be able to read out the quote of the
day of a real Internet server from MCU memory by using the flash emulation tool (FET).
*(unsigned char *)RemoteIP = 24; // destination IP: 24.8.69.7
*((unsigned char *)RemoteIP + 1) = 8;
*((unsigned char *)RemoteIP + 2) = 69;
*((unsigned char *)RemoteIP + 3) = 7;
TCPLocalPort = 2025; // local TCP port doesn’t matter (>1024)
TCPRemotePort = 17; // standard port: “quote of the day”
TCPActiveOpen();
while (SocketStatus & SOCK_ACTIVE) // wait for closing the connection by the
{ // other TCP
DoNetworkStuff();
}