Pages: [1]   Go Down
Author Topic: Simultaneous SPI Devices  (Read 1870 times)
0 Members and 1 Guest are viewing this topic.
London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I am trying to run an SD Card and the WIZ820io Ethernet interface on an Arduino Mega 2560
Both work separately but as soon as I add
Code:
pinMode(10, OUTPUT);
digitalWrite(10, LOW);
the ethernet interface stops working
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 512
Posts: 26202
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Each device needs its own Slave Select line.
Typically these seem to D10 and D4 on shields.
Check what each device is using.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
With just ethernet device plugged in I enabled the SS pin as an output even if i put it low it stops working, does the ethernet library control this because I had a look on an oscilloscope without mentioning the SS pin and it seemed to output 3.3V but drop it to low whenever there was communication between the two.
Logged

Offline Offline
God Member
*****
Karma: 17
Posts: 721
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So what is a slave select pin supposed to do in your opinion?

I think it's supposed to go low whenever there is communication to let that particular slave know that it is supposed to be the recipient.  Then by high when the slave is not being selected.
Logged

Germany
Offline Offline
Edison Member
*
Karma: 129
Posts: 1434
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I recently attached two SPI devices (SD Card and LCD) i noticed, that the chip select is not the only problem. Both devices (i mean their libs) did use a different and incompatible SPI setup. And both libs did this setup only during their lib startup phase. This forces me to save the SPI state of both libs and restore the settings, depending which device i want to access next.

Oliver
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

By "incompatible" do you mean that for example they use different clock edges or something?

If so you could re-run their .begin() funcs each time but that's a bit of a crappy way to do it. As you say you could remember the port state and change back and forth.

But the LCD is a slow device, why not use shiftOut() to talk to it or are you reading data from it as well?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Germany
Offline Offline
Edison Member
*
Karma: 129
Posts: 1434
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Indeed the LCD (16x2, doglcd lib) uses Software SPI (something like shiftout). But SdFat makes use of the HW SPI. On the board both devices are connected to the same SPI pins (with different chip select signals). To use the doglcd lib, I had to disable the SPI subsystem. To use SdFat I had to restore the HW SPI .


Oliver


 
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8471
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
On the board both devices are connected to the same SPI pins
This doesn't make sense if one device is using software SPI. Just move the LCD to different pins if you have spare ones.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It turns out that if I set the SS pins for the SD.h lib and the Ethernet.h lib (4 and 10 respectively) then they don't work.  However if I don't mention anything in the setup they work fine.  And the oscilloscope confirms that all the selections seem to be done automatically.  Aaaaannnnddd everything works together.  smiley-lol
Logged

0
Offline Offline
Shannon Member
****
Karma: 198
Posts: 11620
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A good SPI library would change the SPI settings (clock mode, clock speed) automatically whenever necessary - not sure I've seen one that does this.  You also have to ensure every device has its CS line high before any SPI transfers are performed.

The more fundamental problem with SPI libraries is when you want to use SPI in an interrupt routine (not unusual with RF transceivers for instance) - you then need to inhibit interrupts around other calls to the SPI primitives, or some other anti-collision scheme.
Logged

[ I won't respond to messages, use the forum please ]

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 512
Posts: 26202
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Find a better LCD library that uses real SPI.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to run [...] the WIZ820io Ethernet interface on an Arduino Mega 2560
Both work separately [...]

Hello mrjonny2
Can you tell me, please, in detail how you ran WIZ820io on Mega 2560?
WIZ820io is R1.0 ?!
What version of the IDE, Mega, WIZ, libraries, etc...
Pins to pins connection, plz

Thanks!!!
Logged

London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
Sorry for sporadic replies, exam period and all ;(
I am using the module with a 2560 at the moment.
The pinout I am using is:
MISO - 50
MOSI - 51
SCLK - 52
nSS - 10

I am using an arduino mega pro (3.3V version from spark fun)
Version 1.0 of the IDE
Make sure you give it 3.3V Power
Make sure you have the updated libraries - http://www.wiznettechnology.com/sub_modules/en/product/Product_Detail.asp?cate1=5&cate2=42&cate3=0&pid=1161#tab

I can't remember if there were any other changes I had to make to the library, because I had some error messages thrown up but I can't remember what they were. Let me know if you have any other problems.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 87
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello friends.
You are just the greatest. smiley-grin smiley-grin smiley-grin smiley-grin
Now I have searched and searched for how to do and then I came to your thread. and now it works. IIIIIIHHHAAAAAAAAA many thanks for that you are here smiley-lol smiley-lol smiley-lol smiley-lol
Logged

Pages: [1]   Go Up
Jump to: