View previous topic :: View next topic |
Author |
Message |
sunmat
Joined: 02 Nov 2010 Posts: 51
|
Posted: Thu Feb 28, 2013 2:34 am Post subject: Arduino Ethernet shield not working with atMega1280 ? Modbus |
|
|
Hi!
I write ModbusTCP server protocol using Arduino uno R3 and cheap 10$ Ethernet shield with W5100. It work GREAT! Fast response to Twincat PLC too.
This is setup, nothing fancy, I just copied from some TCP example file:
Code: | $projecttime = 64
'$regfile = "m32def.dat" ' chip used
'$regfile = "m16def.dat" ' chip used
$regfile = "m328pdef.dat"
'$regfile = "m1280def.dat"
$hwstack = 128
$swstack = 128
$framesize = 64
' For different boards
'$Crystal = 8000000
'$Crystal = 11059200
'$Crystal = 12288000
'$Crystal = 14745600
$Crystal = 16000000 ' ARDUINO UNO R3
'$Crystal = 18432000 ' MY Board with AtMega1280
'$Crystal = 22118400
Debug off
'****************************************************************
' MCU hardware configuration
'****************************************************************
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
'Init the spi pins
Spiinit
'Enable Interrupts ' before we use config tcpip , we need to enable the interrupts
Config Tcpip = NOINT , Mac = 00.128.12.34.56.79 , Ip = 192.168.40.70 , Submask = 255.255.255.0 , Gateway = 192.168.40.1 , Localport = 502 , Tx = $55 , Rx = $55 , Chip = W5100 , Spi = 1 |
Then I move "program" to bigger board and bigger CPU, and change setup as folow:
Code: | $projecttime = 69
'$regfile = "m32def.dat" ' chip used
'$regfile = "m16def.dat" ' chip used
'$regfile = "m328pdef.dat"
$regfile = "m1280def.dat"
$hwstack = 128 ' default use 32 for the hardware stack
$swstack = 128 ' default use 10 for the SW stack
$framesize = 64 ' default use 40 for the frame space
' For differnt boards
'$Crystal = 8000000
'$Crystal = 11059200
'$Crystal = 12288000
'$Crystal = 14745600
'$Crystal = 16000000 ' ARDUINO UNO R3
$Crystal = 18432000 ' MY Board with AtMega1280
'$Crystal = 22118400
Debug off
'****************************************************************
' MCU hardware configuration
'****************************************************************
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
'Init the spi pins
Spiinit
Config Tcpip = NOINT , Mac = 00.128.12.34.56.79 , Ip = 192.168.40.70 , Submask = 255.255.255.0 , Gateway = 192.168.40.1 , Localport = 502 , Tx = $55 , Rx = $55 , Chip = W5100 , Spi = 1 |
So I changed only CPU definition and clock. Someone my notice I dint use interrupts, but it workin nicely without.
And... Program not working. No PING response from W5100. I had chacked my hardware VERY carefully at leat 5 times. Logic probe on SS pin show low lewel after restart.
This is connection to Ethernet Shield from my board:
+5V and GND
atMega1280 pins 19,20,21,22 (ss, mosi, miso, sck) to ethernet shields pins 10,11,12,13.
I didn't connected Reset pin since ethernet shiald boards has its own reset circuit.
Also have to say that I use UTP and RJ54 connection from atMEga1280 board to ethernet shield, 50cm long.
I have tryed to change clock rate, but not phase and polarity, since I presume it should work with that parameters, since I have no problem with Arduino board. Even tryed tu use interrpts as in sample, but nothig help. When returning shield to Ard. UNO it work again.
Only have option to reduse SPI cable to 10cm, but I thinq this would not solve problem. And maybe try on arduino Mega, but I don't have with me right now.
Any idea why same program and same hardware connection not wrking on atMEga1280 ? |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Thu Feb 28, 2013 7:40 am Post subject: |
|
|
first step, before init W5100, should be to reset the Chip with a portpin. After that wait for at least 300ms! then do your config to w5100.
best, michael _________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
sunmat
Joined: 02 Nov 2010 Posts: 51
|
Posted: Thu Feb 28, 2013 9:11 am Post subject: Reset with port pin |
|
|
I had try that in way that before I uppload program to atmega, I reset W5100 with on board button. A also try to wait 10 (!) seconds before "spi config" line, and before "tcp config" line too, without help.
Reset with port pin... How....where to connect signal for reset?
I connected all pins which are already connected from arduino board which are +5, ss, mosi, miso, sck.
Why everythng is working on arduino board if I have to wait 300ms, which I not doing as you can see from program....
Confusing ... |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Thu Feb 28, 2013 11:01 am Post subject: |
|
|
Hi,
maximum SPI clock speed should be 4MHz by using W5100
with Mega1280 you changed xtal to 18432000 Hz that meens: 18432000 / 4 (SPI clock divider) = 4608000
too fast
best, michael _________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
sunmat
Joined: 02 Nov 2010 Posts: 51
|
Posted: Thu Feb 28, 2013 2:59 pm Post subject: Clock division..... |
|
|
Thank you Michael for help !
But, I'm sorry, I forgat to mention that I had tryed all clock divisions also.
p.s. But I'll change chrystall 8Mhz internal to try..... |
|
Back to top |
|
|
sunmat
Joined: 02 Nov 2010 Posts: 51
|
Posted: Fri Mar 01, 2013 3:17 am Post subject: Solution.... |
|
|
All "misterious problems" at the end, have simple solution. In my case, it is unproper reading documentation.
I connected control pins (miso, mosi, sck) directly to PORTB connector on ethernet shield, assuming this signals are connected to W5100 from there. But, control pins in case of this shield are connected only to SPI connector, except SS pin, which is connected to digital IO 10, or PORTB.2.
After add some extra wires, now W5100 hapily working even on sligtly increased frequency. At least respond to ping every second.
Thank you Michael for help...
Regards !
Mladen |
|
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
|
|