You are on page 1of 187

TCP/IP ENC28J60

April 26th, 2006


Philip Seo
CAE, Microchip Korea

2006 Corporate Seminar : TCP/IP

Contents
Advanced
Advanced Solutions
Solutions Selling
Selling

Ethernet Overview
Ethernet Overview
Microchip Ethernet Solution
LAB 1 : Configuring the Network

TCP/IP Stack Overview


Network Concept
Basic TCP/IP Review
Networking Concept

Microchip TCP/IP Stack & HTTP Server

Microchip TCP/IP Stack Overview


Microchip File System
Lab 2 Using Microchip File System
HTTP Server
Lab 3 Using HTTP to monitor & control
Lab 4 Using HTTP to download info
Lab 5 Custom UDP application

2006 Corporate Seminar : TCP/IP

Ethernet Overview

2006 Corporate Seminar : TCP/IP

Ethernet

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

Connectivity Summary

AGP
PCI

Today
Tomorrow

1394-Fire Wire

Unlikely

WiFi (b/g)
10Mb/s

Ethernet

USB 2.0
LS-USB
CAN

Page 5

HS-USB

USB 1.1

Serial
500 Kb/s

FS-USB

Parallel Port
1 Mb/s

1.5 Mb/s

12 Mb/s

100 Mb/s 480 Mb/s 1 Gb

Why Ethernet?
z
z

Ethernet is the most widely deployed network in


offices and industrial buildings
Ethernets infrastructure, interoperability and
scalability ensure ease of development
Once equipment is connected to a Ethernet
network, it can be monitored or controlled
through the Internet

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

How does Ethernet work?


z

Carrier Sense Multiple Access w/Collision Detect


- Carrier Sense - each interface must wait
until there is no signal before transmitting
- Multiple Access - all interfaces have equal
priority on the network
- Collision Detect - when interfaces transmit
simultaneously, the collision is detected and
the data is retransmitted
Collisions are normal & expected events
- Interfaces wait random amounts of time to
retransmit

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

Ethernet Market Trends


z

Industrial and businesses are already wired

Ethernet is the de-facto standard for wired comms

No longer PC centric

Ethernet speeds will continue to increase

Installation costs high but installed base is massive

Wireless is in its infancy

VOIP allows speech over the internet

Voice Over Internet Protocol is the fastest growing area

Wireless VOIP is new but will be significant

Page 8

Applications
z
z
z
z
z
z
z
z
z
z

Page 9

Fire & Safety Panels


Industrial Control
Access Control
Industrial printer
Label printer
Hotel minibar
Home automation
VOIP intercom
Metering
Speakers

z
z
z
z
z
z
z
z

Environmental monitoring
Kitchen appliances
Drink dispenser
Network monitoring
Instruments
Server monitoring
Fingerprint recognition
Medicine dispensing

Ethernet Installations

Where else would you find Ethernet installed?


Commercial buildings (Retail / Warehousing etc)
Industrial (Factories etc)
Offices
Hotels
Homes

Bridges

z
z
z
z
z

Page 10

CAN Ethernet
Zigbee Ethernet
USB Ethernet

Market Drivers
z

Industrial Applications:

Access control
Security cameras
Fire panels
Industrial Printers

VoIP:

Smart Card Reader

Zellweger Gas Detector

Adapters
Phones
Security Cameras

Page 11

Printers

Power Over Ethernet


z

Powers devices connected to Ethernet


New Market
Does not require mains to be routed to device
Reduces installation costs greatly
Reduces cable runs
It a worldwide standard

Ethernet Clock

48 Volts

Zellweger Gas Detector


Security Cameras

Page 12

Smart Card Lock

Smart Card Reader

VoIP Phone Adapter

ADSL
ADSL

COMPUTER

ADSL MODEM

Page 13

VoIP Phone Adapter


Router

VOIP Adapter

ADSL
ADSL

COMPUTER

Standard wired phone

Page 14

Standard wired phone

VoIP Phone Adapter

Page 15

Page 16

ENC28J60
Product Summary
z

Worlds Smallest Ethernet Controller:

Minimizing board space, cost, complexity

Optimised for Embedded Solutions

ENC28J60 highly integrated

Microchip offers FREE TCP/IP Stack

Page 17

On-chip 10Mbps MAC/PHY, 8Kb Buffer RAM, SPITM


serial interface, 28-pin package

Modular design, no license/royalty fees

ENC28J60: Ethernet Controller

Provides Remote Application Access


Page 18

ENC28J60
Worlds Smallest Ethernet Controller!
MAC Address from IEEE $1500

MCU

INT, WOL

Page 19

Serial Ethernet Controller


DIP, SOIC, SSOP, QFN

MCU

8Kbytes

IEEE 802.3

INT, WOL

Vdd range =>3.14 to 3.45V


2005 Microchip Technology Incorporated. All Rights Reserved.

Temperature => 0C to 70C


Class

Slide

20

ENC28J60 Block Diagram

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

21

ENC28J60 External Connection

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

22

ENC28J60 Register Map

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

23

ENC28J60 Memory

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

24

ENC28J60 External Connection

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

25

ENC28J60 Transmit Packet Layout

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

26

ENC28J60 Receive Packet Layout

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

27

ENC28J60 SPI Instruction Set

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

28

ENC28J60 SPI READ

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

29

ENC28J60 SPI WRITE

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

30

VoIP Phone Adapter


DS

Current Part is a standard


Network Interface Card IC

SOIC, SDIP, SSOP,QFN

Competitive 10 Mbps,
100-pin Device
Page 31

Microchip 10 Mbps,
ENC28J60: 28 Pins

Ethernet PICtail #AC164121:


Supporting Demo Boards
Future PICDEMTM II+
$99

PICDEM FS USB - $59


Page 32

PICDEM HPC Explorer -$59

PICDEM LCD - $125

Ethernet PICtailTM

PICDEM Z - $199

Competition Summary

Page 33

Parallel Ethernet Controllers


z

RTL8019AS
-

CS8900A
-

IEEE 802.3 10Mbit


16Kbytes RAM, 100-pin QFP
ISA Bus
IEEE 802.3 10Mibt
4Kbytes RAM, 100-pin QFP
ISA Bus

LAN91C111
-

IEEE 802.3/802.3u 10/100 Mbit


8Kbytes RAM, 128-pin QFP
ARM, PowerPC, MIPS 32-bit interface

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

34

Ethernet PICTailTM Daughter Board

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

35

Ethernet PICTailTM Daughter Board

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

36

dsPICDEM.net Board
ICD2
UART

10-base T
Ethernet

LCD

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

37

dsPIC30F Ethernet
Controller Connection (1 of 2)
PORTD

PORTD

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

38

dsPIC30F Ethernet
Controller Connection (2 of 2)

PORTD
Data I/O

Control
Register
Address

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

39

Microchip
s PICDEM.net
Microchips
z

PICDEM.net Kit includes:


z
z
z
z
z
z
z

PICDEM.net board
PIC16F877
TCP/IP Lean book
Users Guide
Power Adapter
Ethernet Cable
PICDEM.net Connectivity
Solutions CD
-ROM
CD-ROM

Price: $299USD

40

**Hardware
Hardware Overview
PICDEM.net Block Diagram
USER LEDs
D6
VCC
RB5
/MCLR

S3
S2

AN0/RA0
AN1/RA1

A2
VCC
A1
WP
A0
SCL
GND SDA
24LC256

SCL
SDA

JP2

RA2
RA3
RE2
RE1
RE0
RD7-0
RB4-0

RSTDRV LED2
LED1
LED0

D5

1
6
RC6/TXD
RC5(CTS)
RC7/RXD
RC2(RTS)
PIC18F452
19.66MHz

T1IN T1OUT
T2IN T2OUT
R1OUT R1IN
R2OUT R2IN
TC232

2
7
3
8
4
9
5

Not all connections shown


41

IOWB TPout+
IORB
SD7-0
TPoutSA4-0
TPin+
SA19-SA5
TPinRTL8019
20MHz

D3
D2
D1

RJ45

Explore 16 + Ethernet Demo Kits

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

42

Integrated MCU + Ethernet


z

PIC18F97J60
- 64K, 96K or 128K bytes Flash z
- 3.9K bytes RAM
- 8K bytes TX/RX Buffer
- 41.67MHz max
Package (TQFP)
- 64/80/100-Pins
Other:
- External Memory Bus
- 16 channel 10-bit A/D
Communication
- Ethernet: MAC+PHY
(IEEE 802.3 10BASE-T)
- 2 EUSARTs
- MSSP (SPI /MI2C)
2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Peripherals
-

16 ch. 10-Bit ADC


2 Comparators
5 Timers
CCP/ECCP modules

Slide

43

LAB1 : Configuring our Network

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

44

LAB1 : Ethernet Demo Kit Connection


PC/Laptop running:
Optional

RJ-11 Phone Cable

MPLAB IDE for ICD2


IE for displaying HTML pages

USB Cable

CAT-5 Crossover Cable


Ethernet
Connection
ICD 2 Jack
PICDEM HPC Explorer Board
running Microchip TCP/IP Stack program
45

LAB1 : Go to Network Connections

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

46

LAB1 : Network Connections


Properties

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

47

LAB1 : Local Area Connection


Properties

Click this
button

Highlight this
selection

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

48

LAB1 : Internet Protocol (TCP/IP)


Properties

Copy these
numbers

Select this
option
10 . 10 . 5 . 16

10 . 10 . 5 . 15

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Make sure the


last number
is board + 1

Slide

49

Lab #1
z
z
z

Goal: Setup Computer & Board


Open LAB.PJT in C:EthernetLAB
Edit address
- S1 + RESET Button : Menu Selection
- Select 2. Change default IP address
- Insert New IP Address -> Enter

z
z

Compile & Download program


Open Internet Explorer, Type in IP address
of your board

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

50

TCP/IP Stack Overview

2006 Corporate Seminar : TCP/IP

What is a network?
z

network

a computer or telecommunications
system linked to permit exchange of
information

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

52

What is a network?
z

internet

(Lower case i) any time you connect 2 or


more networks together, you have an
internet - as in inter-national or interstate
Also known as a network

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

53

What is a network?
z

intranet

a network operating like the World Wide


Web but having access restricted to a
limited group of authorized users (as
employees of a company)

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

54

What is a network?
z

Internet

(Upper case I) The vast collection of


inter-connected networks that all use the
TCP/IP protocols and that evolved from
the ARPANET of the late 60s and early
70s
The Internet now connects roughly 60,000
independent networks into a vast global

internet

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

55

What is a network?
z

LAN

a computer network limited to the


immediate area, usually the same building
or floor of a building

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

56

What is a network?
z

WAN

any internet or network that covers an


area larger than a single building or
campus

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

57

What devices make up a


network?
z

client

software used to contact and obtain data


from Server software on another computer
designed to work with one or more
specific kinds of Server programs, and
each Server requires a specific kind of

Client

a Web Browser is a specific kind of Client

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

58

What devices make up a


network?

z
z

server
a computer or software package that
provides services to clients running on
other computers
can refer to a particular piece of software
or to the machine which is running the
software
A server machine can run different server
software packages providing many
different servers to clients on a network

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

59

What devices make up a


network?
z

router

a special-purpose computer or software


package that handles the connection
between 2 or more networks
routers spend all their time looking at the
destination addresses of the packets
passing through them and deciding which
route to send them on

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

60

What devices make up a


network?
z

gateway

protocol converter
an application-specific node that
connects otherwise incompatible
networks
converts data codes and transmission
protocols to enable interoperability
between networks

2001 Microchip Technology Incorporated. All Rights Reserved..

S4601

Internet Connectivity

61

Basic TCP/IP Review


Internet Protocol Stack
SNMP

(T)FTP

HTTP

UDP

SMTP

Internet Layer

USART

- implements addressing

and routing for transmitting/receiving data

IP

Modem

- implements reliable

communication over the Internet Layer

ICMP

SLIP

- web browsers,

email and other user oriented services

Transport Layer

TCP

PPP

Application Layer

DHCP

Network Access Layer

ARP

- manages HW

interface to communications medium


Physical Layer - communications
medium such as telephone wires,
CAT-5 cable, etc.

Ethernet

62

Internet Protocol Stack Layers


z
z
z
z
z

Physical Layer - communications medium such


as telephone wires, CAT-5 cable, etc.
Network Access Layer - manages hardware
interface to communications medium
Internet Layer - implements addressing and
routing for transmitting and receiving data
Transport Layer - implements reliable
communication over the Internet Layer
Application Layer - web browsers, email and
other user oriented services
63

Basic TCP/IP Review


z

Protocol
PPP
IP
TCP
UDP
SMTP
FTP
HTTP

Description
Point-to-Point Protocol
Internet Protocol
Transmission Control Protocol
User Datagram Protocol
Simple Mail Transfer Protocol
File Transfer Protocol
Hyper Text Transfer Protocol

RFC

Request For Comment

For a complete glossary, search the RFCs, go to:


http://www.ietf.org/rfc/rfc1983.txt?number=1983
64

Basic TCP/IP Review


IETF RFCs Recommended Reading List
RFC

Description

172 FTP
768 UDP
791 IP
793 TCP
821 SMTP
937 POP3
1055 SLIP

File Transfer Protocol


User Datagram Protocol
Internet Protocol
Transmission Control Protocol
Simple Mail Transfer Protocol
Post Office Protocol
Nonstandard for transmission of IP
datagrams over serial lines
Protocol walkthroughs
Protocol walkthroughs
The Point-to-Point Protocol
The PPP Internet Protocol Control Protocol
Authentication Protocols
Trivial File Transfer Protocol
Dynamic Host Configuration Protocol
Bootstrap Protocol
Hyper-Text Markup Language
(http://www.w3c.org/)

1122
1123
1331, 1661 PPP
1332 IPCP
1334 PPP
1350 TFTP
1541 DHCP
1542 BOOTP
2854 HTML

65

Ethernet Packet

Used in the
calculation
of the FCS

Number
of Bytes

Field

Preamble

Comments
Filtered out by the MAC

SFD

Start-of-Frame Delimiter
Filtered out by the MAC

DA

Destination Address

SA

Source Address

Type/Length

461500

Data

Type of Packet or the


Length of the Packet

Packet Payload
(with optional padding)

Padding
4
2005 Microchip Technology Incorporated. All Rights Reserved.

FCS

Frame Check Sequence - CRC


Class

Slide

66

Physical Layer
z

Physical Layers

Takes many forms


z Telephone Line (modem, DSL)
z Twisted pair, coaxial, fiber optic, RF
(Ethernet)
Supports many data rates
z Modem - up to 56 Kbps
z Ethernet - up to 1 Gbps

67

Network Access Layer


z

Network Access Layer - PPP (RFC 1661)

Point-to-Point Protocol

most well known as a protocol that allows a


computer to use a regular telephone line and a
modem to make TCP/IP connections to the

Internet

68

Network Access Layer


z
z

Network Access Layer - DHCP (RFC


1541)
Dynamic Host Configuration Protocol

a protocol for assigning dynamic IP addresses


to devices on a network

Network Access Layer - ARP (RFC 826)


Address Resolution Protocol

z
z

protocol used to convert an IP address into a


physical address (i.e. Ethernet address)
69

Internet Layer
z

Internet Layer - IP (RFC 791)

Internet Protocol

specifies the format of packets, also called


datagrams, and the addressing scheme
Handles routing of data over the arbitrary
collections of networks called the Internet
Most networks combine IP with a Transport
Layer protocol, which establishes a virtual
connection between a destination and a source

z
z

70

IP Header Format
0

0 Version
Hdr len Service
8 Time
to live
16

20

Pcol

Length

Ident

Checksum

8
Flags
Fragment Offset

Source Address

Destination Address
Header options
0 - 40 bytes
IP data
0 - ? bytes
Header length is default 20 bytes long
71

Internet Layer
z

Internet Layer - ICMP (RFC 792)

Internet Control Message Protocol

an extension to IP
Handles transfer of messages containing error,
control, and informational data
PING, for example, is a ICMP echo request/reply
to see if a computer exists

z
z

72

Transport Layer
z

Transport Layer - UDP (RFC 768)

User Datagram Protocol

a connectionless protocol that runs on top of IP


networks
provides very few error recovery services,
offering instead a direct way to send and
receive datagrams over an IP network
used primarily for broadcasting messages over
a network

73

UDP Packet Format


0
0

Source Port

Destination Port

Message Length

Data

74

8
Checksum

Transport Layer
z

Transport Layer - TCP (RFC 793)

Transmission Control Protocol

one of the main protocols used in networks


enables two hosts to establish a connection and
exchange streams of data
guarantees delivery of data and also guarantees
that packets will be re-assembled in the same
order in which they were sent

z
z

75

TCP Functions
z

Why is TCP so difficult?


z
z
z
z
z
z
z
z
z
z
z

Initiate a connection between two computers


Send data bi-directionally between 2 computers
Handle loss of data on the network
Handle duplication of data on the network
Handle reception of packets out of order
Handle network failure
Handle data rates from single byte to bulk transfers
Provide flow control to prevent data overload
Close connection between 2 computers
Support partially closed connection
Handle data arrival after connection closed
76

TCP Packet Format


0
0

16

20

Source Port

Destination Port

Urgent Pointer

Options

Data

77

Sequence Number
Header
Length

Acknowledgement Number

Checksum

Flags

Window

Applications Protocols
z

In addition to the basic protocols,


application protocols allow
communication of information
z
z
z
z

Mail
Web browsing
Network management
File Transfer

Application protocols run on top of the


basic protocols
78

Application Layer
z

Application Layer - SMTP (RFC 821)

Simple Mail Transfer Protocol

a protocol for sending email messages between


servers
generally used to send messages from a mail
client to a mail server

79

Application Layer
z

Application Layer - HTTP (RFC 2616)

HyperText Transfer Protocol

underlying protocol for World Wide Web


defines how messages are formatted and
transmitted, what actions web servers and
browsers should respond to commands
enter a URL in web browser, sends an HTTP
command to the Web server directing it to fetch
and transmit the requested web page

80

Application Layer
z

Application Layer - TFTP (RFC 1350)

Trivial File Transfer Protocol

a simple form of the FTP


uses UDP and provides no security features
often used by servers to boot diskless
workstations, X-terminals, and routers

z
z

81

Networking
z

Three ways to communicate


- Wired dial-up
- SLIP, PPP, etc.
- Wireless Ethernet
- 948 WLC presented by Fred Eady
- www.edtp.com
- TRENDnet TEW-222CF 802.11b RF card
- Wired Ethernet
- Subject of this class

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

82

Network Topologies
z

Serial link
z

Three wires connect computers together


z Ground
z A transmit to B receive
z B transmit to A receive

B
83

Network Topologies
Serial Link
z
z
z
z
z
z
z

Both computers have equal access to the link


There are only two computers on the network
A computer can transmit data at any time
Message delivery is reliable
The serial data is a free-format stream of bytes,
with little or no integrity checking
There is no limit on message size
There is no need for addressing

84

Network Topologies
Serial Link
z
z
z

TCP/IP assumes data is sent in blocks


with defined beginning and end
Serial driver resides on top of serial link
Serial Line Internet Protocol
z
z
z

End of each block signaled by a C0h byte


Most SLIP drivers send C0h at beginning to clear out
any garbage characters
Maximum 1006 bytes per block

SLIP frame END


C0h

Data
1 - 1006 bytes
85

END
C0h

Network Topologies
z

Network
z
z

Computers are connected to a common


cable or to a hub
A hub copies the signals and is essentially
transparent to the computer

Network - bus topology

Network - star topology


86

Network Topologies
Network (Ethernet)
z
z
z
z
z
z
z

All computers on the network have equal access to the


network
All computers have a unique 48-bit address
Any computer may transmit on the network when it is
idle
Message delivery is unreliable
All data on the network is in blocks (frames) with a
defined beginning and end and integrity check
The network can send a maximum of 1500 bytes per
frame
All messages are equipped with a source and
destination address
87

Network Topologies
Network (Ethernet)
z

Ethernet frames include


z Destination address
z Source address
z Type/Length field
z Data
z CRC
Dest
6 bytes

Source
6 bytes

Type
2 bytes

Data
46 - 1500 bytes

Ethernet frame 64 - 1518 bytes


88

CRC
4 bytes

TCP Packet Format


Bytes
0

Source Port

Destination Port

Sequence Number
Header
Length

Acknowledgement Number
16

Checksum

Urgent Pointer

20

Options

Data

89

Flags

Window

UDP Packet Format


Bytes
0

Source Port

Destination Port

Message Length

Data

90

8
Checksum
(Ignore: 0x0000)

IP Header Format
Bytes
0

0 Version
Hdr len Service
8 Time
to live

Pcol

Length

Ident

Checksum

8
Flags
Fragment Offset

Source Address

16

Destination Address
20

Header options
0 - 40 bytes
IP data
0 - N bytes
Header length is default 20 bytes long
91

Transporting TCP/IP
Ether

IP

TCP/UDP

User Payload

16 bit
checksum

16 bit
checksum

92

CRC

Transporting TCP/IP
Ether

IP

TCP/UDP

User Payload

16 bit
checksum

CRC

16 bit
checksum

Handled by datalink (hardware and/or software)

93

Transporting TCP/IP
Ether

IP

TCP/UDP

User Payload

16 bit
checksum

z
z

CRC

16 bit
checksum

Handled by datalink (hardware and/or software)


Handled by stack (segment discard on checksum f
ail)

94

Transporting TCP/IP
Ether

IP

TCP/UDP

User Payload

16 bit
checksum

z
z
z

CRC

16 bit
checksum

Handled by datalink (hardware and/or software)


Handled by stack (segment discard on checksum f
ail)
Handled by stack (checksum test deferred)
Checksum appears in header
z
Value set so overall sum is FFFF
z

95

Transporting TCP/IP
Ether

IP

TCP/UDP

User Payload

16 bit
checksum

z
z
z

CRC

16 bit
checksum

Handled by datalink (hardware and/or software)


Handled by stack (segment discard on checksum f
ail)
Handled by stack (checksum test deferred)
Checksum appears in header
z
Value set so overall sum is FFFF
z
Passed to application
Data streamed up as it arrives
z
Checksum pass/fail notified at end of data
z
96

Network Diagram

ROUTER
SUBNET 1
SUBNET 3
ROUTER

ROUTER
SUBNET 2
LINK TO OTHER NETWORK
ROUTER
97

Physical Layer Addressing


z

Ethernet
z
z
z

z
z

Each device on the network has a unique six


byte physical address
Highly specific to the hardware
Upper 3 bytes are Organizationally Unique ID
z Buy from IEEE for $1500
Lower 3 bytes are serial number
Cumbersome to use to transfer information
z Need a logical address
98

Internet Layer Addressing


z

IP Address
z
z

Uses the Network Access Layer protocols to


assign logical address to physical address
4 byte number represents:
z Network address - uniquely identifies an
organization
z Subnet address - identifies a subnet
within the organization
z System address - identifies a single
node on the subnet
99

Network Addressing
z

Network needs to know if the recipient is


on the same subnet
z
z

Does it send the message directly


Does it sent the message through a router

Each node has a subnet mask


z

Logically ANDed with IP address &


compared
Node 2
Node 1
123.45.67.8
123.45.78.9
IP Address
255.255.255.0 255.255.0.0
Subnet Mask
123.45.0.0
Resulting Subnet 123.45.67.0
100

Connection Orientated Model (TCP)


1. Request
Connection

3. Session Established,
Transmit Data Units

5. Transmit n
Data Units

7. Done,
disconnecting

Originating host
Internet

Destination host
2. Connection acknowledged
Request n Data Units
z

4. Received,
send n more.

6. Received,
send n more

8. OK, terminating
session

TCP provides Connection


-orientated services to upper layer TCP/IP and
Connection-orientated
User applications
101

Connectionless Model (UDP)


1. Ready or not, Im sending
n data units to you

2. Done

Originating host

Internet

Destination host

UDP provides Connection


-LESS services to upper layer UDP/IP and User
Connection-LESS
applications
102

Why TCP/IP?
z

z
z
z

Not the only option (CAN, ARC, MODBUS,


proprietary), but certainly the most popular
one. Basis for the Internet. The role of
private LANs.
Suitable for most but not all applications
Benefit from the wide availability of tools
and expertise
TCP vs. UDP if TCP guarantees delivery,
and UDP is unreliable,
unreliable, why is UDP still
around ? Critical application design
decisions
103

Delivery Guarantees
z
z
z
z
z
z
z
z
z
z
z
z
z
z

TCP provides ordered reliable delivery


bi
-directional connection
-orientated protocol
bi-directional
connection-orientated
data is segmented and acknowledged
flow control via a window
window
sequence numbering on content
timeouts and re
-transmits
re-transmits
larger memory footprint
UDP is accepted best
-effort
best-effort
low overhead, connection
-LESS protocol
connection-LESS
transaction orientated (transmitter to receiver)
application must address reliability (no ACK)
packet delivery is not guaranteed
use for periodic data transmissions
smaller memory footprint

104

TCP versus UDP


TCP
z

UDP

Takes elaborate measures


to ensure reliable delivery,
mandating use of specific
timers and thus effectively
defining the behavior of
the data transfer.
Especially appropriate for
transfer of file
-like data
file-like
(firmware, etc.) which
must arrive intact but not
necessarily time
-critical.
time-critical.
Larger memory footprint
footprint..

105

Thin layer on top of IP


protocol. Does not
guarantee delivery. Many
realreal- time
time protocols
built on top of UDP to
obtain the precise timing
and reliability
requirements for a
particular application
(RTSP for example).
Much smaller memory
footprint.

Microchip TCP/IP Stack &


File System Overview

2006 Corporate Seminar : TCP/IP

Introduction to Microchips TCP/IP


Stack

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

107

Microchip FREE TCP/IP Stack


z
z

Runs on most PIC18 micros


Requires approx 25K Code space

z
DHCP

SNMP

HTTP

UDP

TCP
ICMP
IP
ARP
Ethernet

Page 108

FTP

TFTP

Stack is license FREE


Application Notes:
z AN833
z AN870

Microchips TCP/IP Stack


z
z

Microchip App Note AN833 & AN870


Source code available for FREE !
- No fee license agreement
- Must use with Microchip MCU
- Download off Microchip website

z
z

Standard Microchip technical support


Suite of files
- C Source files and PC based utility

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

109

What can I do?

Provides Remote Application Access


2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

110

TCP/IP Stack Features


z
z

Portable across PIC18 microcontrollers


Out-of-box support for Microchip
MPLAB C18 and PICC 18 (Hitech)
compilers
- Additional support for PIC24 & dsPIC

RTOS independent Cooperative


Multitasking Environment
Modular Design
- Full TCP State machine
- Socket support for TCP and UDP

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

111

Stack Modules
Internet Protocol Stack
DHCP SMTP* SNMP

UDP

HTTP FTP

Application Layer

TCP

Transport Layer

ICMP

Internet Layer

IP
PPP*
Modem*

SLIP
USART

ARP
Ethernet

Network Access Layer


Physical Layer

* To be added
2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

112

Block Diagram
Server

Application

Custom

Transport

FTP

Client

Server

SMTP HTTP

Stack Manager

TCP/UDP
ICMP
IP

Internet

ARPTask
ARP
Host-To-Network

2005 Microchip Technology Incorporated. All Rights Reserved.

MAC

Class

Slide

113

Media Access Control (MAC)


z

Out-of-box support for:


-

ENC28J60
RealTek 8019AS
SMSC LAN91C111

Uses many of Microchips demo boards


including PICDEM.net & dsPICDEM.net
Uses NIC RAM as buffer
Data

MCU

Address

Ethernet
Interface

Control
2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

114

IP Configuration
z
z

IP Address, Subnet Mask, Gateway


Static values
- Hard-coded in source code

IP Gleaning
- Only IP address

Dynamic Host Configuration Protocol


- All IP parameters
- Fully automatic

Function calls to MAC

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

115

Transmission Control Protocol


(TCP)
z

Connection Oriented
- Reliable data transfer

z
z

Full TCP State Machine


Unlimited TCP Sockets
- Limited by available RAM and compiler only

Function calls to:


- MAC
- IP

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

116

TCP Functions
z
z
z
z
z
z
z
z
z

TCPInit
TCPListen
TCPConnect
TCPIsConnected
TCPDisconnect
TCPIsPutReady
TCPPut
TCPFlush
TCPIsGetReady

2005 Microchip Technology Incorporated. All Rights Reserved.

z
z
z
z
z

Class

TCPGet
TCPGetArray
TCPDiscard
TCPProcess
TCPTick

Slide

117

TCP Client Steps


ARPResolve(...)

TCPIsPutReady(..)

TCPIsGetReady(..)

TCPPut(...)
TCPFlush(...)

TCPGet(...)
TCPDiscard(...)

ARPIsResolved(..)

TCPConnect(...)
TCPDisconnect(...)

TCPIsConnected(..)
TCPIsConnected(..)

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

118

TCP Server Steps


TCPListen(...)

TCPDisconnect(...)
TCPIsConnected(..)

TCPIsConnected(..)

TCPIsPutReady(..)

TCPIsGetReady(..)

TCPPut(...)
TCPFlush(...)

TCPGet(...)
TCPDiscard(...)

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

119

User Datagram Protocol (UDP)


z

Connectionless Protocol
- No built-in error recovery

Unlimited UDP Socket support


- Socket count limited by available RAM
- Multiple applications can access UDP
simultaneously

z
z

No checksum calculation
Function calls to:
- MAC
- IP

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

120

UDP Functions
z
z
z
z
z
z
z
z
z
z

UDPInit
UDPOpen
UDPClose
UDPIsPutReady
UDPPut
UDPFlush
UDPIsGetReady
UDPGet
UDPDiscard
UDPProcess

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

121

UDP Steps
UDPOpen(...)

UDPIsPutReady(..)

UDPIsGetReady(..)

UDPPut(...)
UDPFlush(...)

UDPGet(...)
UDPDiscard(...)

UDPClose(...)

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

122

Security
z
z

z
z
z

No built-in security
Application must provide reasonable
authentication and encryption
Avoid blind remote control
Restrict critical commands
PIC microcontroller is not same as PC
- Limit no. of users to designed limit
- No built-in solution for Denial Of Service

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

123

Microchip TCP/IP Stack Configure

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

124

Microchip TCP/IP Stack Configure

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

125

Microchip TCP/IP Stack File

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

126

Microchip TCP/IP Stack File

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

127

**Microchip
Microchip TCP/IP Stack

Compile
-Time Options (Module
Compile-Time
Selection)

STACK_USE_ DHCP Custom FTP SNMP HTTP


DHCP
SNMP
FTP_SERVER
HTTP_SERVER

StackTsk.h
Stack Manager

TCP/UDP
TCP / UDP
MAX_SOCKETS
MAX_UDP_SOCKETS

ICMP
IP_GLEANING

ICMP

IP
ARPTask
IP_GLEANING

MAC
128

ARP
SLIP
SLIP

**Microchip
Microchip TCP/IP Stack

Compile
Time
Options
Compile-Time
MAX_HTTP_CONNECTIONS StackTsk.h

DHCP Custom

FTP SNMP HTTP

Stack Manager

TCP/UDP
TCP_NO_WAIT_FOR_ACK
STACK_CLIENT_MODE

MAX_ICMP_DATA_LEN ICMP
IP
ARPTask
STACK_CLIENT_MODE

MAC_TX_BUFFER_SIZE
MAC_TX_BUFFER_COUNT

MAC
129

ARP
SLIP

**Microchip
Microchip TCP/IP Stack

Compile
-Time Options
Compile-Time

TCP_NO_WAIT_FOR_ACK

Allows back
-to-back TCP packet
back-to-back
transfers (within a TCP window) while
waiting for ACK
Throughput increased TCP
Don
t care: HTTP
Dont

z
z

browser always
retries
ACK
Client

Server
130

**Microchip
Microchip TCP/IP Stack

Compile
-Time Options
Compile-Time

Server and/or client?


z

Two modes of operations


z
z

z
z

STACK_CLIENT_MODE enables Client mode


Client mode provides
z
z
z

Server
Server and Client

TCPConnect
ARPResolve
ARPIsResolved

SMTP module enables Client mode


131

**Microchip
Microchip TCP/IP Stack

Software Structure

z
z

void main(void) {

while(1){

z
z

Tasks

// Main infinite loop


// Cooperative Multitasks
//
RTOS Independent

z
z

// Initialization

Initialization

}
// Int service routines

ISRs
// Subroutines

Subroutines
132

**Microchip
Microchip TCP/IP Stack

Software Structure Initialization

z
z
z
z
z
z
z
z
z

MyInit();
StackInit();
TickInit();
HTTPInit();
dependent
MPFSInit();
FTPInit();
DHCPInit();
SNMPInit();

//
// Your
//

Initialization
app init
Required

// Application

133

**Microchip
Microchip TCP/IP Stack

Software Structure - Main Loop


z
z
z

while(1){
// Main infinite loop
MyTask();
// Your app task(s)
StackTask();
// Required

HTTPServer();
dependent

FTPServer();
DHCPServer();
SNMPServer();

z
z
z

}
134

// Application

**Microchip
Microchip TCP/IP Stack

Software Structure - Subroutines


z
z

TickUpdate();

HTTPExecCmd();
dependent
HTTPGetVar();

// Subroutines
// Required

// Callbacks app

135

**Stack
Stack Layers

Application - HTTP Server API


z

HTTPGetVar
z

Callback function to get dynamic variable value

Used when client requesting info from server

Client

Server
136

Microchip TCP/IP Stack Usage

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

137

Microchip File System

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

138

Microchip File System


(MPFS)
z
z

Small yet powerful file system


Flexible storage scheme
- Internal program memory or external data
EEPROM (up to 64KB)

z
z
z
z

PC based utility to generate MPFS image


8 + 3 Short file names
Case-insensitive file names
Read AN833 for more detail

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

139

Microchip File System


(MPFS)

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

140

MPFS Image
z

Two types
- C data file for Program Memory
- bin file for external data EEPROM

z
z
z
z
z

PC utility mpfs.exe
All web pages in one directory
Image size must fit in available memory
CR LF stripped from *.htm files
Reserved block for application specific
data

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

141

MPFS Utility
z

mpfs [/?] [/c] [/b] [/r<Block>]


<InputDir> <OutputFile>
/? : Display help
/c : Generate C data file
/b : Generate binary data file (Default)
/r : Reserve a block of memory at beginning
(Used in /b mode only. Default=32)
- <InputDir>: Directory that contains files
- <OutputFile>: Output file name

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

142

MPFS Examples
z

Generate C data file


- mpfs /c MyPagesDir mypages.c
- Link this file into your project

Generate binary data file, with 32 bytes


reserved block
- mpfs MyPagesDir mypages.bin

Reserve 128 bytes in EEPROM


- mpfs /r128 MyPagesDir mypages.bin
- Useful to store custom data outside MPFS

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

143

Lab #2
z
z

Goal: Learn how to modify MPFS image


Exercise:
- Modify name in
c:EthernetLABwebpagesmain.htm
- Build MPFS image
- mpfs c:EthernetLABwebpages
webpage.bin
- Download new webpages using
HyperTerminal
- Open Internet Explorer and type in Board IP
Address

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

144

LAB2 : Downloading Web Pages


with Hyperterminal
z
z
z

Open HyperTerminal
File -> Properties
Connect using:
-

z
z
z
z
z

Select COM port

Select Configure
Use same options ->
Click OK
Click OK
Connect ->

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

145

LAB2 : Downloading Web Pages


with Hyperterminal
Press & Hold S1, Press & Release MCLR, Release S1

Select 7
2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

146

LAB2 : Downloading Web Pages


with Hyperterminal
Select Transfer -> Send File

C:\Ethernet\LAB\webpages.bin

Pulldown menu & select Xmodem


Browse & select this file Click Send
2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

147

LAB2 : Downloading Web Pages


with Hyperterminal
Select 8 to Finish

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

148

HTTP Servers

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

149

HTTP Server
z
z
z
z

Multiple simultaneous connections


Supports HTML Forms
Dynamic web page creation
Pages stored in Program Memory or
external serial EEPROM
Simple and powerful Microchip File
System (MPFS)
Easy to integrate

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

150

HTTP Server API


z
z

HTTPInit
HTTPServer
- Performs HTTP Server tasks - Call
periodically

HTTPGetVar
- Callback to get dynamic variable value

HTTPExecCmd
- Callback to execute HTML form command

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

151

Web content
z
z

Static HTML pages and graphics


Interactive pages
z
z

Clickable graphics
Forms

Dynamic pages
z
z
z
z

Common Gateway Interface


Embedded Gateway Interface
Server-side inclusion
Variable substitution

152

Static HTML pages


z
z
z

Stored in EEROM filesystem


Copied from ROM to network
ROM contains
z

File directory
z Location
z Length
z Attributes
z Pre-calculated TCP checksum
File
z HTTP header
z Data
153

Interactive HML pages


z

Clickable graphics

<table><tr valign=middle>
<td><a href="switch2.htm"><img src="switchu.gif"></a></td>
<td><img src="ledoff.gif"></td>
</tr></table>
154

Interactive HTML pages


z

HTML forms

GET /thank.htm?name=Joe+Bloggs&addr=joe@home&
state=happy&send=Submit HTTP/1.0

155

Display variable substitution

@3

&deg;C

becomes
23.5&deg;C

@2:@1:@0
becomes
20:44:19

156

Form variable substitution


<form action='setime.egi'>
<input type=text name=hrs
size=2 value='@2'> :
<input type=text name=min
size=2 value='@1'> :
<input type=text name=sec
size=2 value='@0'>
<br><br>
<input type=submit name=sub
value='Set clock'>
</form><br>

157

Button value substitution

<form action='digout.egi'>
<table border=2><tr>
<td><input type=submit
name=out7 value=#></td>
<td><input type=submit
name=out6 value=#></td>
<td><input type=submit
name=out5 value=#></td>

</tr></table></form>

158

ChipWeb home page

z
z
z
z

159

Monitor digital I/Ps


Control digital O/Ps
Display analog values
Use conventional Web
browser

Navigation frame

z
z

Standard HTML techniques


Change page in the center frame
<A href="main1.htm" target=middle>
Home</A>

Animate switches and LEDs


<td><a href="digout11.htm"> <img s
rc="sw0.gif"></a></td>
<td><a href="digout00.htm"> <img s
rc="sw1.gif"></a></td>

160

Dynamic status frame


z

Update page using client pull


<meta http-equiv="refresh" content="5">

Dynamic data using @ variables


<tr><th>O/P states</th></tr>
<tr><td>@5</td><td>@6</td></tr>

Dynamic graphics using stacked GIFs

161

Dynamic HTML Pages


z
z
z
z

Must have cgi file extension


Variable substitution method
Format: %xx - xx is a variable (0-99)
Substitution may be one or more
characters
- May be used to upload complete binary
image

Use extra % to display % itself


- 23%% displays 23%

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

162

Variable Substitution Example


z
z
z
z
z
z

1. <table>
2. <tr><td><b><Results></b></td></tr>
3. <tr><td><Pot1:></td><td>%02</td></tr>
4. <tr><td><Pot2:></td><td>%03</td></tr>
5. <tr><td><Switch:></td><td>%04</td></tr>
...
%02
%03
%04

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

163

Dynamic HTML Pages - Uses


z

Change web page content


- ...Serial Number=%01

Change graphics based on a variable


- img src=LED%02.gif

Change page link


- <a href=%02.htm>LinkName</a>

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

164

HTTPGetVar
z

(BYTE var, WORD ref, BYTE *val)

Data transferred byte at a time


ref is used for multi-byte transfers

- First transfer with ref =


HTTP_START_OF_VAR
- return other than HTTP_END_OF_VAR to
indicate multi-byte transfer
- Finish data transfer by returning
HTTP_END_OF_VAR

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

165

HTTPGetVar Example
z
z
z
z
z
z
z
z
z
z

(BYTE var, WORD ref, BYTE *val)


1. if (var == 4) // Identify variable.
2. { // Return 1 if switch is open, else
0
3.
if ( RB5 ) *val = 1;
4.
else *val = 0;
5.
return HTTP_END_OF_VAR;
6. }
7. else
8. // Check for other variable...
...

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

166

Multi-byte transfer
z
z
z
z
z
z
z
z
z
z
z

(BYTE var, WORD ref, BYTE *val)


1. if (var == 1) // Identify var.
2. { // If this first call, init array index.
3.
if ( ref == HTTP_START_OF_VAR ) ref = 0;
4.
// Stuff current byte in buffer.
5.
*val = SerialNumberStr[(BYTE)ref];
6.
if ( *val ==\0 ) return HTTP_END_OF_VAR;
7.
return ++ref;
// Advance array index
8. }
9. else // Check for other variable...
...

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

167

Lab #3
z

Goal: Use command execution via


browser and how to dynamically change
web pages
Exercise:
- Modify c:EthernetLABMainDemo.c
- Implement HTTPExecCmd() callback to
toggle LEDs D5, D6 when Toggle LED1 and
Toggle LED2 buttons are pressed
- Change status.cgi to display graphical LED
state led0.gif for OFF and led1.gif for ON

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

168

HTML Forms
z

Interactive HTML pages


- Data is transferred from PC to PIC18
microcontroller

Form method GET only

Remote command invocation


- User application must implement the
command

Caution: Multiple users may execute same


command simultaneously
- Must protect critical data

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

169

Form Example
z
z
z
z
z
z
z

z
z

P, %07

1. <FORM METHOD=GET
action=command.cgi>
2. <table>
3. <tr><td>Power Level:</td>
4. <td><input type=text size=2
maxlength=1 name=P value=%07></td></tr> ...
5. <tr><td><input type=submit name=B
value=Apply></td></tr> ...
B

Action by browser when Apply is clicked


10.10.5.110/command.cgi?P=5&L=1&H=255&B=Apply

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

170

HTTPExecCmd
z
z
z
z

(BYTE **argv, BYTE argc)


argv[0] = Form Action Name
argv[1argc] = Parameter 1 to argc
argc = Number of parameters including
Form Action Name
command.cgi?P=5&L=1&H=255&B=Apply
- argv[0] = command.cgi, argv[1] = P,
argv[2]= 5 etc ; argc = 9
- argv[0] determines page to be uploaded
next

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

171

HTTPExecCmd Example
z
z
z
z
z
z
z
z

z
z
z

(BYTE **argv, BYTE argc)


1. for ( i = 1; i < argc; i++ ) {
2.
if ( argv[i][0] == P ) // Power setpoint ?
3.
PowerVal = atoi(argv[++i]); // Save value
4. else if ( argv[i][0] == L ) // Low setting ?
5.
LowPowerSetting = atoi(argv[++i]); // Save
6. else if ( argv[i][0] == H ) // High setting ?
7.
HighPowerSetting = atoi(argv[++i]); // Save
}
}
// If required, another page may sent as a result
strcpy(argv[0], RESULTS.CGI); // Set result page

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

172

Form Fields Limit


z

Allowable max. number of arguments


- FormAction?Arg1=Val1+Arg2=Val2
- See MAX_HTTP_ARGS & MAX_HTML_CMD_LEN
in http.c

Default
- MAX_HTTP_ARGS = 5 (Includes action)
- MAX_HTML_CMD_LEN = 80

If limit is exceeded,
- Extra arguments are ignored

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

173

Lab #4
z

Goal: Learn about PC to PIC data transfer


using forms
Exercise:
- Implement code in HTTPExecCmd() to
accept User Name from Output Control and
save it to PIC microcontroller RAM
- Implement code in HTTPGetVar() to display
saved User Name in System Status page.

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

174

Custom Application

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

175

Lab #5
z

Create the Sensor


- Receives UDP packets that change
PORTD<5>
- Receives request for status (PORTD<5> and
AN0)
- Serves web page on local status

Presenters board
- Collects information from each sensor
- Serves web page displaying all sensors info

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

176

Lab #5
z

z
z
z

Add source code to MainDemo.c, see


flow chart on next page
Compile project
Download into board
Run & wait for instructor

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

177

UDP Process
UDPIsGetReady(..)

UDPPut(LATD5?1:0)

EXIT
YES

UDPPut(AN0String[x])

UDPGet(&UDPChar)
UDPDiscard()

UDPFlush(...)
NO

UDPIsPutReady()

EXIT

UDPChar == 0xAA

YES

YES

NO

YES

UDPChar == 0x55

LATD5 ^= 1;
NO
2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

178

Summary
z

z
z
z

Overview of Ethernet and Ethernet


controllers
Intro to the Microchip TCP/IP Stack
Using the Microchip File System
Using HTTP Servers to monitor, control
and download information
Designing Custom Applications

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

179

References
z
z

AN833 The Microchip TCP/IP Stack


AN870 An SNMP Agent for the Microchip
TCP/IP Stack
DM163004 PICDEM.net Internet/Ethernet
Demonstration Board
DM300004-1/2 dsPICDEM.net 1/2
Connectivity Demonstration Board
ENC28J60 Ethernet PICTail

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

180

MAC Functions
z
z
z
z
z
z
z
z
z

MACInit
MACIsTxReady
MACGetHeader
MACGet
MACGetArray
MACDiscardRx
MACPutHeader
MACPut
MACPutArray

2005 Microchip Technology Incorporated. All Rights Reserved.

z
z
z
z
z
z
z
z

Class

MACFlush
MACDiscardTx
MACSetRxBuffer
MACSetTxBuffer
MACReserveTxBuffer
MACGetFreeRxSize
MACGetRxBuffer
MACGetTxBuffer

Slide

181

IP Functions
z
z
z
z
z
z
z

IPIsTxReady
IPSetTxBuffer
IPPutHeader
IPPutArray
IPGetHeader
IPGetArray
IPSetRxBuffer

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

182

Dynamic Host Configuration


Protocol (DHCP)
z

Fully automatic method


- Node gets configured on power-up
- Automatic IP renewal

Needs at least one DHCP Server on


network
Configures
- IP, Gateway Address, Subnet Mask

Solves Embedded Systems Problem


- Discovery of IP Address

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

183

Simple Network Management


Protocol (SNMP)
z
z
z
z

Manage network devices: server, printer etc.


Machine-to-machine protocol
Supports SNMPv1 over UDP
Protocol of choice for small embedded systems

Network
Devices
Manager

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

184

Web Page Types


z

Page file extension defines how browser


displays/interprets the page
- Default support for txt, htm, gif, cgi,
jpg, cla, wav.
- If needed, modify httpFiles and
httpContents in http.c file

index.htm is the default web page


- Defined by HTTP_DEFAULT_FILE_STRING in
http.c file

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

185

Web Page Design Guidance


z

Avoid using excessive files in a page


- More simultaneous connections
- More RAM usage

Hand-code the pages


- Or remove unnecessary tags generated by
visual web authoring tool

Try to shrink the graphics


- Use correct file formats

Auto refresh dynamic content only

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

186

Q/A
.

2006 Corporate Seminar : TCP/IP

You might also like