Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem with Arduino Mega2560 and Ethernet Shield (W5100)

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
sielcon

Bascom Member



Joined: 16 Mar 2006
Posts: 74
Location: Argentina

argentina.gif
PostPosted: Tue Apr 11, 2017 4:11 pm    Post subject: Problem with Arduino Mega2560 and Ethernet Shield (W5100) Reply with quote

Hello everyone, the problem is the following, I am doing a simple UDP communication, after initializing SPI, TCP, etc. I run GETSOCKET and SCKETSTAT without any problems, after about 30 seconds or when I send a package it is reset.
I have enabled the interruption of the W5100 that goes to PE.4 of 2560.
I did a lot of testing and I can not get it to work, thank you if anyone can help me.
I attach the code and the result of the terminal.
Thank you very much.


Code:

'-----------------------------------------------------------------------------------------
'name                     : udptest.bas
'copyright                : (c) 1995-2005, MCS Electronics
'purpose                  : start the easytcp.exe program after the chip is programmed and
'                           press UDP button
'micro                    : Mega161
'suited for demo          : no
'commercial addon needed  : yes
'-----------------------------------------------------------------------------------------

$regfile = "m2560def.dat"                                   ' specify the used micro

$crystal = 16000000                                         ' used crystal frequency
$baud = 19200                                               ' use baud rate
$hwstack = 64                                               ' default use 32 for the hardware stack
$swstack = 64                                               ' default use 10 for the SW stack
$framesize = 50                                             ' default use 40 for the frame space

Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
'Init the spi pins
Spiinit

Dim Idx As Byte
Dim Leng_udp As Word                                        ' result
Dim Buf_udp(80) As Byte
Dim Sstr As String * 20
Dim Temp As Byte , Temp2 As Byte

Print "Init , set IP to 192.168.1.15"                       ' display a message
Enable Interrupts                                           ' before we use config tcpip , we need to enable the interrupts
Config Tcpip = Int4 , _
       Mac = 12.128.12.34.56.78 , _
       Ip = 192.168.1.15 , _
       Submask = 255.255.255.0 , _
       Gateway = 192.168.1.1 , _
       Localport = 5000 , _
       Tx = $55 , Rx = $55 , _
       Chip = W5100 , _
       Spi = 1 , _
       Cs = Portb.4
Idx = Getsocket(idx , Sock_dgram , 5000 , 0)                ' get socket for UDP mode, specify port 9092
Print "Socket:" ; Idx
Leng_udp = Socketstat(idx , Sock_closed)
Print "Stat:" ; Hex(leng_udp)

Do
Leng_udp = Socketstat(idx , Sel_recv)                       ' get number of bytes waiting

   If Leng_udp > 0 Then
      Print "Leng:" ; Leng_udp
      Temp2 = Leng_udp - 8                                  'the first 8 bytes are always the UDP header which consist of the length, IP number and port address
        Print
        Print Peersize ; " " ; Peeraddress ; " " ; Peerport ' these are assigned when you use UDPREAD
        Print Ip2str(peeraddress)                           ' print IP in usual format

      Temp = Udpread(idx , Buf_udp(1) , Leng_udp)           ' read the result
      Print "Error:" ; Temp
      For Temp = 1 To Leng_udp
          Print Chr(buf_udp(temp));
      Next Temp
      Print
   End If
Loop
End


Init , set IP to 192.168.1.15
UDP demo
Socket 0
Bytes waiting : 771

Peersize = 0
Peeraddress = 0.0.0.0
Peerport = 0
read 0
Init , set IP to 192.168.1.15
UDP demo
Socket 0
Bytes waiting : 771

Peersize = 0
Peeraddress = 0.0.0.0
Peerport = 0
read 0


(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.7.8 )
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Apr 11, 2017 8:26 pm    Post subject: Reply with quote

you need to use Udpreadheader for the w5100.
you best start with a sample from the samples\tcpip\w5100 folder

you can best use Config Tcpip = NOINT
or increase the $hwstack

_________________
Mark
Back to top
View user's profile Visit poster's website
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue Apr 11, 2017 11:38 pm    Post subject: $stack and $framesize... W5100 Reply with quote

The first thing I noticed, you should increase $stacks en $framesize.

Check on other examples.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
sielcon

Bascom Member



Joined: 16 Mar 2006
Posts: 74
Location: Argentina

argentina.gif
PostPosted: Wed Apr 12, 2017 2:04 am    Post subject: Reply with quote

Hello Mark, thank you very much for your quick response. Probe your suggestions regarding stack and NOINT but nothing changes. Then probe the PING_SPI.BAS and if it worked, later probe the UDP_SWITCH_SPI_MEGA.BAS and it did not work either. In all cases do the same as I said in my previous post. For the doubts also change the whole HARD but nothing change, it would seem that the problem is when it reads UDP because in the example PING_SPI.BAS uses Udpwrite and it works.
Also run another application that developed some time ago and does not work. It's very strange, I wanted to try with an earlier version of BASCOM but I do not have any.
Hope someone can help me.
Best regards.
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Apr 12, 2017 1:15 pm    Post subject: Reply with quote

you need to pay attention to this :

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


when using an old UDP sample for the W3100 you need to include the UDPREADHEADER

_________________
Mark
Back to top
View user's profile Visit poster's website
sielcon

Bascom Member



Joined: 16 Mar 2006
Posts: 74
Location: Argentina

argentina.gif
PostPosted: Tue Apr 18, 2017 12:38 pm    Post subject: Reply with quote

Dear Mark, I am using W5100, I also use UDPHEADER but the results do not change, it transmits without problems but when it receives the CPU is reset. The strangest thing is that if through EASYTCP send data to another IP is also reset.
Best regards
Back to top
View user's profile Visit poster's website
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue Apr 18, 2017 1:13 pm    Post subject: Questions about hardware Reply with quote

Still some questions:

Are you using an Arduino Mega 2560 with W5100 Ethernet shield?
Do you have other shields on it?
How is the power to this board managed? An USB cable? Power through the external Arduino jack? 7-12 volt? Enough amps?

Have you checked the software on a similair board?

You have changed the code, stacks etc, is it possible to show your latest version?

Fusebits?

Ben Zijlstra
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Apr 18, 2017 1:43 pm    Post subject: Reply with quote

Im the author of this video and can confirm that there is no any problem for programming arduino boards Mega2560 and even Uno328P for WS5100 and UDP communication. Look that even my tablet get acces to this Arduino boards via WiFi

The problem is in Your code.
My program it is written once, but by configuring (IP, Gate, ports, etc.) with AT commands it allows you to use it on multiple boards.

I can pack this program and share but if you resolve problem by searching in your code an learn something, give you more satisfaction Very Happy
Back to top
View user's profile Visit poster's website
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue Apr 18, 2017 1:58 pm    Post subject: Some more to 'PEEK' Reply with quote

EDC

Before there were libraries I have written software for the W5100 and AVR. But exact as you stated perhaps the best to first get this hardware running.

If you want to have a peek at what 'I' did (it started with a small program from Thomas Held), here is that page

http://members.home.nl/bzijlstra/software/examples/wiz810mj.htm

My two cents
Ben Zijlstra
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Apr 18, 2017 2:06 pm    Post subject: Reply with quote

@bzijlstra

I know Your work Ben Wink
There is even polish tutorial how to play with ENC28J60 writted by Piotr Rzeszut and You get special thanks in this publication on the first page Very Happy

So I am full of respect for your work Very Happy
Thanks.
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Apr 18, 2017 2:20 pm    Post subject: Reply with quote

A crash : check your power supply.
_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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