Pages: [1]   Go Down
Author Topic: Sharing SPI bus wth ethernet shield  (Read 1251 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all

Has anyone experience of using the SPI bus for the ethernet shield (W5100) and another SPI device? Are the ethernet and SPI libraries robust in releasing CS when they can?

I want to also connect an NRF24L01 transceiver and use the ethernet to do some remote logging and control.

Thanks

Peter
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31458
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can always do the SPI transfers using other pins and just bit bang them, there is no need to use the dedicated hardware.

Here is some idea of the code to use on any GPIO:-

Code:
void spiWrite(byte data){
  shiftOut(MOSI, SCK, MSBFIRST, data); // send to spi output
}

byte spiRead(){
  byte value=0;
  for(int i = 0; i<8; i++){
    digitalWrite(SCK,LOW);
    value = value << 1; // shift up for next byte read
    value |= ( digitalRead(MISO) & 0x1); // add the next bit to the value
    digitalWrite(SCK,HIGH);
  }
      digitalWrite(SCK,LOW);  // put clock low at the end
  return value;
}
Logged

Rural Arizona
Offline Offline
Edison Member
*
Karma: 7
Posts: 1711
Incorrigible tinkerer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There's a known problem with the Wiznet modules not releasing the MISO line when deselected.

I don't remember,  offhand,  whether it's a bug in the chip design or the module design.  This matters because not all Ethernet shields use the module (the Adafruit ones I have do,  but some have the 5100 chip right on the shield).

I think I've seen some postings indicating some people have worked around this,  but I haven't pursued it because I haven't been hit by the problem in the projects I've done so far.
Logged

0
Offline Offline
Faraday Member
**
Karma: 7
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's a chip flaw.  They added an enable pin to do what it's supposed to do when you take CS inactive.

Some shields drive this line in conjunction with CS so that the shield behaves correctly (i.e. takes MISO hi-Z).

-j
Logged

Middle of the Pacific
Offline Offline
Full Member
***
Karma: 0
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was able to find a work around for this problem.

All you need to do is tie your CS for the secondary SPI device to
to the PROG jumper (or place where a jumper should be) on the ethernet shield.  This effectively shuts off the SPI interface on the WIZNET and pulls MISO into a high impedance state.

The prog jumper has two pins, you will want to connect to the one that is not tied to ground.

I hope this helps.
Logged

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

All

Thanks for the great info and ideas. I've ordered some of the radio modules and will report back on progress once I have them.

Best regards

Peter
Logged

Pages: [1]   Go Up
Jump to: