View previous topic :: View next topic |
Author |
Message |
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Mon Jun 03, 2013 7:44 pm Post subject: WIZ820i0 |
|
|
I try to do my first project with TCP/IP. I tried all samples but nothing working. FOr example the code below. Ping working but UDP communication not. I check communication with the Easy TCP/IP
Code: | $Regfile="m1284pdef.dat"
$Crystal=8000000
$hwstack=80
$swstack=64
$framesize=80
$baud = 19200
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
Spiinit
Config PinB.2 = Output
W5200_nreset Alias PortB.2
Set W5200_nreset
Config PinB.3 = Input
W5200_nint Alias PortB.3
Reset W5200_nreset
Waitms 1
Set W5200_nreset
Waitms 350
Print "Init TCP"
Enable Interrupts
Config Tcpip = Noint , _
Mac = 0.11.22.33.44.55 , _
Ip = 172.18.0.200 , _
Submask = 255.255.255.0 , _
Gateway = 172.18.0.1 , _
Localport = 5000 , _
Chip = W5200 , _
Spi = 1 , _
Cs = PortB.4
Dim Idx As Byte ' socket number
Dim Result As Word ' result
Dim S(255) As Byte
Dim Sstr As String * 255
Dim Temp As Byte , Temp2 As Byte ' temp bytes
Const Showresult = 1
Print "UDP demo"
Dim Ip As Long
Ip = Maketcp(172.18.0.51) 'assign IP num
'like with TCP, we need to get a socket first
'note that for UDP we specify sock_dgram
Idx = Getsocket(idx , $02 , 5000 , 0) ' get socket for UDP mode, specify port 5000
Print "Socket " ; Idx ; " " ; Idx
'UDP is a connection less 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 compare to TCP/IP you send exactly the same, but with the addition of the IP and PORT
Do
Temp = Inkey() ' wait for terminal input
If Temp = 27 Then ' ESC pressed
Sstr = "Hello"
Result = Udpwritestr(ip , 5000 , Idx , Sstr , 255)
Elseif Temp = 32 Then 'space
Do
Waitms 200
Dim Tel As Long : Incr Tel
Sstr = "0000000000111111111122222222223333333333 " + Str(tel)
Result = Udpwritestr(ip , 5000 , Idx , Sstr , 255)
Loop
End If
Result = Socketstat(idx , Sel_recv) ' get number of bytes waiting
If Result > 0 Then
Print "Bytes waiting : " ; Result
Udpreadheader Idx ' read the udp header
#if Showresult
Print
Print Peersize ; " " ; Peeraddress ; " " ; Peerport ' these are assigned when you use UDPREAD
Print Ip2str(peeraddress) ' print IP in usual format
#endif
If Peersize > 0 Then ' the actual number of bytes
Print "read" ; Peersize
Temp = Udpread(idx , S(1) , Peersize) ' read the result
#if Showresult
For Temp = 1 To Peersize
Print S(temp) ; " " ; ' print result
Next
Print "done"
#endif
Result = Udpwrite(ip , Peerport , Idx , S(1) , Peersize) ' write the received data back
End If
End If
Loop
'the sample above waits for data and send the data back for that reason temp2 is subtracted with 8, the header size
End |
|
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Mon Jun 03, 2013 8:57 pm Post subject: W5200 SNTP example... |
|
|
With the W5200 I got this running:
Code: | 'Arduino Duemilanove test - Atmega328p
'W5200 - SNTP works
$regfile "m328pdef.dat"
$crystal = 16000000
$baud = 19200 ' use baud rate
$hwstack = 80 ' default use 32 for the hardware stack
$swstack = 128 ' default use 10 for the SW stack
$framesize = 80
$lib "datetime.lbx" 'this example uses date time routines
$loadersize = &H800
'Configuration Of The SPI bus
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
'Init the spi pins
Spiinit
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.70 , Submask = 255.255.255.0 , Gateway = 192.168.0.1 , Localport = 1000 , Tx = $55 , Rx = $55 , Chip = W5200 , Spi = 1 ', Cs = Portb.2
Print "Init done"
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
Print "SNTP demo"
'assign the IP number of a SNTP server
Ip = Maketcp(64.90.182.55 ) 'assign IP num NIST time.nist.gov port 37
Print "Connecting to : " ; Ip2str(ip)
'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
'UDP is a connection less 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 compare to TCP/IP you send exactly the same, 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 5000
Lsntp = Sntp(idx , Ip) ' get time from SNTP server
' Print Idx ; Lsntp
'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 send a diagram too
'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
|
Check also the bascomforum.de Six1 made some code for the WIZ820io in Bascom-AVR.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Mon Jun 03, 2013 9:21 pm Post subject: |
|
|
I do not know. Maybe there is a hardware problem. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Jun 03, 2013 9:26 pm Post subject: |
|
|
make sure reset time is long enough. i know MAK3 had a problem and the longer reset solved it.
Reset W5200_nreset
Waitms 1
Set W5200_nreset
Waitms 350 _________________ Mark |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Tue Jun 04, 2013 3:52 pm Post subject: |
|
|
it did not help |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Tue Jun 04, 2013 8:19 pm Post subject: |
|
|
So, my problem was solved. I had connected ISP programmer parallel to WIZ module. |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Tue Jun 04, 2013 8:45 pm Post subject: wiz820io |
|
|
Great to hear!!
Have fun
Ben Zijlstra |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Wed Jun 05, 2013 7:12 pm Post subject: |
|
|
so, One more problem. I try the sample code servertest_W5200.bas but I cannot connect to WIZ by tool Easy TCP/IP. If I mark check connect, the mark removes itself. |
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Thu Jun 06, 2013 7:05 am Post subject: |
|
|
could someone explain me what is it socket ? Why are there 0 - 7 socket ?
Code: | For Idx = 0 To 7
Result = Socketstat(idx , 0) |
|
|
Back to top |
|
|
MAK3
Joined: 24 Sep 2010 Posts: 449 Location: Germany
|
Posted: Thu Jun 06, 2013 8:34 am Post subject: |
|
|
Hi,
because the W5200 Chip on the WIZ820io provide 8 sockets:
http://www.wiznet.co.kr/Sub_Modules/en/product/Product_Detail.asp?cate1=5&cate2=7&cate3=56&pid=1144
iEthernet W5200 ? Fast SPI Ethernet Controller
- High Speed Serial Peripheral Interface (SPI MODE 0, 3)
- Hardwired TCP/IP Protocols : TCP, UDP, ICMP, IPv4 ARP, IGMP, PPPoE, Ethernet
- 10BaseT/100BaseTX Ethernet MAC/ PHY embedded
- Auto Negotiation ( Full and half duplex, 10 and 100-based )
- Auto MDI/MDIX (Straight-through or Crossover)
- ADSL connection (with support PPPoE Protocol & PAP/CHAP Authentication mode)
- 8 independent sockets simultaneously
- Internal 32Kbytes Memory for Tx/Rx Buffers
- Multi-function LED outputs (Full/Half duplex, Link, Speed)
- Power down mode
- Wake on LAN
- 0.18 μm CMOS technology
- 3.3V operation with 5V I/O signal tolerance
- Lead-Free Package
- Small & Compace 48 Pin QFN Package |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Thu Jun 06, 2013 7:04 pm Post subject: |
|
|
Maybe I don't understand network communication. I try send a string from PC to atmega with UDP protocol. If I press ESC, atmega send the string Hello to PC. It is ok but then I think that the program stay before condition Result because Result = 0. When will value of Result > 0 ?
Code: | $Regfile="m644pdef.dat"
$Crystal=8000000
$hwstack=128
$swstack=128
$framesize=128
$baud = 9600
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
'Init the spi pins
Spiinit
Print "Init , set IP to 172.18.0.200" ' display a message
Config Pinb.2 = Output
W5200_nreset Alias Portb.2
Set W5200_nreset
Config Pinb.3 = Input
W5200_nint Alias Portb.3
Reset W5200_nreset
Waitms 1
Set W5200_nreset
Waitms 350
Enable INTERRUPTS
Config Tcpip = Noint , Mac = 12.128.12.34.56.78 , Ip = 172.18.0.200 , Submask = 255.255.255.0 , Gateway = 172.18.0.1 , Localport = 1000 , Chip = W5200 , Spi = 1 , Cs = Portb.4
'config pinc.1 = output
'portc.0 = 1
Dim Idx As Byte ' socket number
Dim Result As Word ' result
Dim S(80) As Byte
Dim Sstr As String * 20
Dim Temp As Byte , Temp2 As Byte ' temp bytes
'--------------------------------------------------------------------------------------------
'When you use UDP, you need to dimension the following variables in exactly the same order !
'--------------------------------------------------------------------------------------------
Declare Function Ipnum(ip As Long) As String ' a handy function
'like with TCP, 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 connection less 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 compare to TCP/IP you send exactly the same, but with the addition of the IP and PORT
Do
UDPREADHEADER idx
Temp = Inkey() ' wait for terminal input
If Temp = 27 Then ' ESC pressed
Sstr = "Hello"
Result = Udpwritestr(172.18.0.51 , 5000 , Idx , Sstr , 255)
print result
End If
Result = Socketstat(idx , Sel_recv) ' get number of bytes waiting
If Result > 0 Then
Print "Bytes waiting : " ; Result
Temp2 = Result - 8 'the first 8 bytes are always the UDP header which consist of the length, IP number and port address
Temp = Udpread(idx , S(1) , Result) ' read the result
For Temp = 1 To Temp2
Print S(temp) ; " " ; ' print result
Next
Print
Print Peersize ; " " ; Peeraddress ; " " ; Peerport ' these are assigned when you use UDPREAD
Print Ipnum(peeraddress) ' print IP in usual format
Result = Udpwrite(172.18.0.51 , Peerport , Idx , S(1) , Temp2) ' write the received data back
End If
Loop
'the sample above waits for data and send the data back for that reason temp2 is subtracted with 8, the header size
'this function can be used to display an IP number in normal format
Function Ipnum(ip As Long) As String
Local T As Byte , J As Byte
Ipnum = ""
For J = 1 To 4
T = Ip And 255
Ipnum = Ipnum + Str(t)
If J < 4 Then Ipnum = Ipnum + "."
Shift Ip , Right , 8
Next
End Function
End
|
|
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Thu Jun 06, 2013 7:59 pm Post subject: |
|
|
so, If I press ESC, ATMEGA sends to PC "Hello". If I send the string "test" from PC to ATMEGA, the string comes back to PC but why console printing not "Bytes waiting : ", recieved string " test" ? |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Thu Jun 06, 2013 9:00 pm Post subject: |
|
|
the problem is solved. I used Putty terminal instead of Bascom terminal. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|