MCS ELECTRONICS Easy-TCP/IP User manual

MCS ELECTRONICS
Making Things Easy
Easy-TCP/IP
I²C / TWI interface
Version
1.6
Easy-TCP/IP
I²C / TWI interface
Reduces the use f I/O pins
(Only 4 pins needed f r TCP/IP)
C st saving, by reducing
c mp nents
I²C / TWI enables l w c st
micr c ntr llers t interact with
the Internet

2
22
2
M C S E L E C T R O N I C S
Easy-TCP/IP I²C / TWI Interface Guide
1995-2006 MCS Electr nics
www.mcselec.c m

3
33
3
Tab e of Contents
Intr ducti n 4
1. Getting started 5
1.1 Assembling y ur PCB 5
2. C nfiguring the 7010A Adapter 12

4
44
4
Introduction
few years ag MCS Electr nics intr duced Easy-TCP/IP, which gave y u a
way f interfacing AVR micr c ntr llers t the Internet in a fast, c st
effective way. Easy-TCP/IP is n w being used in the w rld f embedded
electr nics.
We are n w intr ducing the Easy-TCP/IP TWI – a TCP/IP interface, which uses nly
a few I/O pins f y ur micr c ntr ller,and requires minimal change in y ur
riginal pr gram c de. Easy-TCP/IP TWI was devel ped in resp nse t ur users’
feedback.
The key advantage f the Easy-TCP/IP TWI is that it nly uses f ur micr pr cess r
pins, i.e., tw I/O pins f r I²C serial c mmunicati ns, and ne interrupt pin and a
reset pin. Thus only 4 I/O pins are needed t implement a full TCP/IP interface.
The previ usly released TCP/IP b ard used ab ut 16 I/O lines, making it nly
suitable f r relatively large AVR c ntr llers. If y u are upgrading an applicati n t
TCP/IP, y u are much m re likely t have 4 I/O pins available than 16. And y u
d n t need much m re r m f r the changes needed in the pr gram c de.
The reducti n f I/O pins f the Easy-TCP/IP TWI makes it sl wer than the EASY-
TCP, but f r a l t f embedded applicati ns high speed is n t a requirement. It’s up
t y u t decide whether y u ch se speed, Easy-TCP r a c mpact and ec n mic
Easy-TCP/IP TWI. Using fewer pins requires that reading and writing be serial
rather than parallel, which makes the TWI interface sl wer than the parallel interface.
This guide will help y u implement Easy-TCP/IP TWI. It assumes y u have s me
experience with the Easy-TCP/IP b ard. If y u have n t, please als read the East-
TCP/IP manual, available fr m www.mcselec.c m. The exact l cati n is :
http://www.mcselec.c m/index.php? pti n=c m_d cman&task=d c_d wnl ad&gid
=97&Itemid=54
N te that Easy TCP/IP-TWI requires the 7010A-Adapter B ard.
The Easy TCP/IP M therb ard is nly intended t test this 7010A-Adapter B ard.
Y u can als use an NM7010A m dule r the W3100A chip in y ur design.
Introduction
A

5
55
5
I
1. Getting started
This chapter explains how to get started with Easy-TCP/IP TWI.
f y u have n experience with TCP/IP please read the TCP/IP manual
available fr m www.mcselec.c m. The TCP/IP manual describes general
issues f TCP/IP and h w t c nfigure and test the EASY-TCP/IP series in
y ur LAN.
The Easy-TCP/IP TWI b ard is meant t give y u a way f experimenting with
TCP/IP and BASCOM. If y u wish t build y ur wn c mplete s luti n we
suggest y u implement the NM7010A Adapter B ard in y ur wn system. The
NM7010A is available fr m www.mcselec.c m
1.1 Assemb ing your PCB
This chapter will take you thru the assembling of your EASY-TCP/IP T I
adapter and mother -board. Soldering the components can be done best in
the order of the part list found on page 7.
On the PCB y u will find pads like this:
When s ldering IC’s r c nnect rs, the square pad marks pin 1. F r capacit rs the
square pad marks the p sitive (+) p le.
CAUTION
We advise y u t use IC s ckets rather than s ldering the IC’s directly t the
PCB. Y u may want t use l w quality IC s ckets f r the ATMegas, since it is
easier t (re-) insert IC’s int l w quality s ckets than int high quality (turned)
s ckets.
Do not insert the IC’s at this time
Chapter
1

6
66
6
MOTHERBOARD LAYOUT (version 1 33)
T find the right p siti n f the c mp nents y u may want t reference this
drawing f the b ard lay ut. It is als printed n the PCB itself.
PARTS LIST EASY-TCP/IP Motherboard (Controller)
Component Description Value
R1
POTENTIOMETER . Only needed when LCD
display is used. 1K
R2, 3 RESISTOR 1/8 W 4K7
R4 RESISTOR 1/8 W 10K
C1, C2, C3, C4 ELCO RADIAL 1uF/16V
C5 ELCO RADIAL 100uF/25V
C6, C8, C9,
C10, C11, C16, CERAMIC CAPACITOR 100nF

7
77
7
C17
C7, C14, C15 ELCO Radial 10 uF/16V
C12, 13
CERAMIC CAPACITOR. Opti nal, nly
needed when y u use an external scillat r. 22pF
Q1
CRYSTAL . Opti nal. Only needed when y u
d n t want t use the micr pr cess r
internal scillat r. 8 MHz
IC4 VOLTAGE REGULATOR 5V 7805
IC5
VOLTAGE REGULATOR 3V3
Only when using NON-SMD Adapter
LM2937ET- 3 3
IC1 ATMEGA32 AVR. Or Mega163, Mega644, etc.
ATMEGA32
IC2
ATMEGA48 AVR r Mega88, Mega8,
Mega168 ATMEGA88
The b ard can be used with a 28 pin micr r a 40 pin micr , but
n t b th at the same time. S nly 1 micr pr cess r may be inserted!
IC3 MAX232 MAX232
B1 BRIDGE RECTIFIER B40R
JP1, JP3, JP5, JP7
PIN HEADER 1X5
JP2 PIN HEADER 1X4
JP4 PIN HEADER 1X8
JP6, JP8 PIN HEADER 1X6
JP9 PIN HEADER 1X16
JP10 AVR ISP HEADER 2X5
Adapter b ard PIN HEADER FEMALE 1X6
J1 POWER CONNECTOR
X1 DB9 CONNECTOR FEMALE DB9FL
Misc 4 spacers and b lts M3x6
PH5, PH6 2 pin header
C18 Opti nal 100 nF capactir 100 nF
RST Reset switch
R5 Resist r 330 330
LED1 LED 3mm Red 3 mm RED

8
88
8
Since there are 2 versions of the Adapter board, we describe them
both
Do not solder the ATMega’s at this time, continue soldering the 7010
Adapter board You are not to solder the micros at all
NON-SMD Adapter b ard
PARTS LIST EASY-TCP /IP 7010A NON-SMD Adapter Board
Component Description Value
R1,2 RESISTOR 1/4W 10K
C1, 2 CERAMIC CAPACITOR 100n
RN2 RESISTOR NETWORK 8 x 10kOHM
C nnect r
PIN HEADER BEWARE:
SOLDER ON TOP LAYER
1X6
S1 DIP SWITCH DIP07 r DIP08
Q1 PNP TYPE TRANSISTOR
BC307/BC557
M1 TCP/IP MODULE NM7010A

9
99
9
SMD Adapter board
PARTS LIST EASY-TCP /IP 7010A SMD Adapter Board
Component Description Value
R1,2 RESISTOR 1/4W SMD 10K
C1, 2 CERAMIC CAPACITOR 100 nF
RN2 RESISTOR NETWORK 8 x 10kOHM
C nnect r
PIN HEADER BEWARE:
SOLDER ON TOP LAYER
1X7
S1 DIP SWITCH DIP08
Q1 PNP TYPE TRANSISTOR SMD
BC857
M1 TCP/IP MODULE NM7010A
IC1 3v3 regulat r SMD BA03

10
1010
10
C3 Tantalium elc 22uF/10V
PH3, PH4 2 pin header
Do not place the adapter board on the main board yet
Note 1 : The adapter b ard is c nnected t the M therb ard with a 6/7-pin
male header. This header must be s ldered n the b ard s it p ints d wnward.
S lder it fr m the t p f the b ard s that it can be inserted int the
M therb ard female header, which will be bel w it.
BEFORE YOU CONNECT THE POWER
Once y u have s ldered all parts, check the PCBs. Rem ve any small s lder
d ts between tracks, check y u have s ldered all the pins and that the s lder
j ints l k shiny (n c ld s lder j ints). All c ntacts sh uld l k g d.
C nnect a p wer supply t the M therb ard. The p wer sh uld be in the range
fr m 7 – 12VDC. The higher the v ltage, the m re p wer must be dissipated by
the regulat r. S 7V is better than 12V but b th will w rk.
The p larity is n t imp rtant since a di de bridge is used. Measure the v ltage
at pin 3 f IC4. It sh uld be 5V. Als measure the v ltage at pin 2 f IC5. It
sh uld be 3.3V. The pin ut f the 3.3V regulat r is the same as the 7805 s be
careful that the pin ut is c rrect if y u plan t use a different 3.3V regulat r.
When y u use the SMD-Adapter b ard, it is n t needed t insert the 3V3
regulat r !
If the v ltage is n t c rrect, disc nnect the p wer and check the b ard.
It is g d practice t use a nut and b lt t fasten each regulat r t the b ard t
pr vide a heat sink.
If the v ltages check ut OK, disc nnect the p wer and place ONE f the
ATMega c ntr llers. (Y u can use ATMega32 r ATMega88 r chips with the
same pin uts) Als place the MAX232. At this p int, it is a g d idea t use a
simple pr gram t utput s mething like “1” then “2” n the serial p rt in a d
l p with a 1 sec nd wait between transmissi ns t ensure that everything is
w rking OK n the m therb ard.
Check that the 7010A adapter b ard has n s lder d ts then c nnect the 7010A
adapter t the main b ard.

11
1111
11
The SMD-Adapter b ard has 7 pins. It has an n b ard 3V3 regulat r. It can
pr vide p wer t y ur wn circuit t . Since the regulat r needs an p wer
s urce f 5V r m re, this adapter b ard has an additi nal pin. It is named 5-
12V n the PCB. When y u set DIP switch 1, y u c nnect the 3V3 regulated
p wer t the VCC pin. D this nly when y u d n t supply the 3V3 V lt via
the VCC pin !
Thus when y u use the NON-SMD Adapter b ard, y u need t insert the 3V3
V ltage regulat r n the m therb ard s the Adapter b ard will get 3V3.
But when y u use the SMD-Adapter b ard which has it’s wn regulat r, y u
must take care that y u d n t cl se DIP switch 1, AND use the 3V3 regulat r
f the m therb ard. It is advised t n t insert the 3V3 regulat r n the
m therb ard in that case. But y u can als leave the DIP switch 1 ff, s the
utputs f the tw regulat rs are n t c nnected t each ther.

12
1212
12
T
2. Configuring the 7010A Adapter
This chapter explains how to configure the 70 0A Adapter.
he nly thing that needs t be c nfigured is the 7010A’s slave
address. This can be d ne with DIP switch S1.
The TWI/I2C slave must have a unique address. The LS bit is used t indicate Read
r Write and cann t be set. Theref re, it is n t c nnected t the DIP switch. As DIP
switches with seven switches are hard t find, the PCB is designed s that y u can
use a DIP switch with 7 r 8 switches. The switch number indicated with “8” is n t
c nnected. When y u ch se t insert a DIP with 7 switches, make sure that
p siti n 1 matches p siti n 1 n the PCB and that p siti n 8 n the PCB remains
pen/unused.
The W3100 chip needs pull up resist rs t specify a ne in its address. When the
DIP switch is in the ON p siti n, it c nnects the W3100 address line t gr und,
thus making it 0. When the switch is pen, the pull up resist r will make the address
line a “1”.
We start by selecting the address 0. We need t cl se all switches, which means that
the switches must be pulled t the right.when the PCB is in the same p siti n as
sh wn ab ve.
Chapter
2

13
1313
13
The “On” n the silk screen f the PCB might n t match the “On” f the DIP
switch. But make sure that the pin numbers f the DIP match the PIN numbers f
the silk.
In the example pr grams, address 128(dec) is used. This is &H80(hex) r
10000000(bin).
As the MSB f the address matches pin 7 f the DIP, this switch must be pulled t
the left s the address line will bec me “1”.
NON-SMD
SMD-Adapter
DIP
PIN
Address line
Address line Remark
1 A1 3V3 t VCC
2 A2 A1
3 A3 A2
4 A4 A3
5 A5 A4
6 A6 A5
7 A7 A6
8 N t
c nnected
A7
A0 f the I2C can never be selected as it
is the R/W bit. It is h wever part f the
I2C slave address.

14
1414
14
The sh wn address is A7=1 , i.e., &B10000000 = &H80 = 128(dec). The switch at
p siti n 8 may be in any p siti n since it is n t c nnected.
This address must be specified with the CONFIG TCPIP c mmand.
Config Tcpip =Int0 ,Mac =12.128.12.34.56.78 ,Ip =192.168.0.8 ,Submask =
255.255.255.0 ,Gateway =0.0.0.0 ,Localport =1000 ,Tx =$55 ,Rx =$55 ,Twi
=&H80 ,Clock =400000
This is in fact the nly difference between a pr gram that uses TWI r the high
speed address m de.
Y u can n w start experimenting with the EASY-TCP/IP TWI b ard. Make sure y u
keep y ur c py f BASCOM up t date in rder t get new samples.
A new sample uses the new SNTP() functi n. T get a precise time.
'-----------------------------------------------------------------------------------------
'name : sntp.bas RFC 2030
'copyright : (c) 1995-2005, MCS Electronics
'purpose : test SNTP() function
'micro : Mega32
'suited for demo : yes
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
'this demo also uses TWI/I2C with PCF8574A to show that the I2C is also available for general use
$lib "i2c_twi.lbx"
'$regfile = "m162def.dat" 'specify the micro used
$regfile ="m32def.dat" ' specify the micro used
$crystal =8000000 ' crystal frequency
$baud =19200 ' baud rate
$hwstack =80 ' default use 80 for the hardware stack
$swstack =80 ' default use 80 for the SW stack
$framesize =80 ' default use 80 for the frame space
Const Sock_stream =$01 ' Tcp
Const Sock_dgram =$02 ' Udp
Const Sock_ipl_raw =$03 ' Ip Layer Raw Sock
Const Sock_macl_raw =$04 ' Mac Layer Raw Sock
Const Sel_control =0 ' Confirm Socket Status
Const Sel_send =1 ' Confirm Tx Free Buffer Size
Const Sel_recv =2 ' Confirm Rx Data Size
'socket status
Const Sock_closed =$00 ' Status Of Connection Closed
Const Sock_arp =$01 ' Status Of Arp
Const Sock_listen =$02 ' Status Of Waiting For Tcp Connection
Setup
Const Sock_synsent =$03 ' Status Of Setting Up Tcp Connection
Const Sock_synsent_ack =$04 ' Status Of Setting Up Tcp Connection
Const Sock_synrecv =$05 ' Status Of Setting Up Tcp Connection
Const Sock_established =$06 ' Status Of Tcp Connection Established
Const Sock_close_wait =$07 ' Status Of Closing Tcp Connection
Const Sock_last_ack =$08 ' Status Of Closing Tcp Connection
Const Sock_fin_wait1 =$09 ' Status Of Closing Tcp Connection
Const Sock_fin_wait2 =$0a ' Status Of Closing Tcp Connection
Const Sock_closing =$0b ' Status Of Closing Tcp Connection
Const Sock_time_wait =$0c ' Status Of Closing Tcp Connection
Const Sock_reset =$0d ' Status Of Closing Tcp Connection
Const Sock_init =$0e ' Status Of Socket Initialization
Const Sock_udp =$0f ' Status Of Udp
Const Sock_raw =$10 ' Status of IP RAW

15
1515
15
Print "Init TCP" ' display a message
Enable Interrupts ' before we use config tcpip , we need to enable the interrupts
Config Tcpip =Int0 ,Mac =12.128.12.34.56.78 ,Ip =192.168.0.8 ,Submask =255.255.255.0 ,Gateway
=0.0.0.0 ,Localport =1000 ,Tx =$55 ,Rx =$55 ,Twi =&H80 ,Clock =400000
Dim Var As Byte 'for i2c test
Dim Ip As Long ' IP number of time server
Dim Idx As Byte ' socket number
Dim Lsntp As Long ' long SNTP time
'--------------------------------------------------------------------------------------------
'When you use UDP, you need to dimension the following variables in exactly the order shown!
Dim Peersize As Integer ,Peeraddress As Long ,Peerport As Word
'--------------------------------------------------------------------------------------------
Print "SNTP demo"
'assign the IP number of a SNTP server
Ip =Maketcp(193.67.79.202 )'assign IP num ntp0.nl.net port 37
'we will use Dutch format
Config Date =Dmy ,Separator =-
'we need to get a socket first
'note that for UDP we specify sock_dgram
Idx =Getsocket(idx ,Sock_dgram ,5000 ,0)' get socket for UDP mode, specify port
5000
Print "Socket " ;Idx ;" " ;Idx
'UDP is a connectionless protocol which means that you can not listen, connect or can get the status
'You can just use send and receive the same way as for TCP/IP.
'But since there is no connection protocol, you need to specify the destination IP address and port
'So compared to TCP/IP you send exactly the same message but with the addition of the IP and PORT
'The SNTP uses port 37 which is fixed in the tcp asm code
Do
'toggle the variable
Toggle Var
Waitms 1000
'now send the value of var to the PCF8574A
I2csend &H70 ,var ,1
'this demonstrates that you can use the TWI for both the IIM7010 and other chips on the bus
'A problem could arise when both chips need to be addressed
'And as the IIM7010 is serviced via an interrupt, the main i2c traffic could slow down the TCP
traffic
Lsntp =Sntp(idx ,Ip)' get time from SNTP server
'notice that it is not recommended to get the time every sec
'the time server might ban your IP
'it is better to sync once or to run your own SNTP server and update that once a day
'what happens is that IP number of timer server is sent a diagram
'it will put the time into a variable lsntp and this is converted to BASCOM date/time format
'in case of a problem the variable is 0
Print Date(lsntp);Spc(3);Time(lsntp)
Loop
End

16
1616
16
The Easy TCP/TWI M therb ard uses the DTR line t c ntr l the RESET f the micr pr cess r. This way
y u can use the MCS B tl ader t reset the b ard aut matic when y u update/l ad the pr gram.
But when y u d n t use the MCS B tl ader, the micr will be reset when DTR is n t made l w. Third
party terminal emulat rs might als set DTR high. When y u want t rem ve this pti n, y u need t cut
a track f the PCB. Y u can disc nnect pin 9 f the MAX-232. Or y u can cut the track n the b tt m f
the PCB. When y u bend pin 9 f IC3, y u d n t need t change the PCB and all pti ns are still usable.
Opti n t rem ve pin 9 Opti n t rem ve track

17
1717
17
M ther B ard

18
1818
18
Adapter b ard

19
1919
19

20
2020
20