Author Topic: Ethernet shield and CS Pin 10  (Read 4477 times)

scott216

  • Newbie
  • *
  • Posts: 41
Ethernet shield and CS Pin 10
« on: July 11, 2014, 02:30:23 PM »
I want to use my Moteino with an Arduino Ethernet Shield.  Looking at the Moteino schematic I see it's using pin 10 for CS on the RFM69 chip.  So I need to use another pin for my Ethernet shield.  The Arduino Ethernet library doesn't let you change the pin.  Anyone have a workaround or a different library that works with the Arduino Ethernet shield?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Ethernet shield and CS Pin 10
« Reply #1 on: July 11, 2014, 05:07:13 PM »
You could cut/rewire the RFM69 CS to another pin and then call RFM69::setCS(byte newSPISlaveSelect).
Otherwise sorry but I haven't used ethernet shields in years.

Antony

  • Newbie
  • *
  • Posts: 8
Re: Ethernet shield and CS Pin 10
« Reply #2 on: July 28, 2014, 12:38:23 PM »
Which pad on the RFM69 to cut, please? I see a little trace from pin 10 disappear under the RFM69 board, but can't see which pad it connects to. I checked Moteino Eagle files hoping to work it out myself, but could not find it (sorry if I missed it).

I also would like to try using an ethernet shield on my moteino, rather than using a Pi or linux box which could be unnecessary for certain remote data gathering that doesn't require data conditioning before uploading to a server. Over at the Arduino forums, it seems changing the ethernet shield CS is likely a little more work than changing the moteino CS for the RFM69 because pin 10 seems hardwired into the atmega chip for ethernet (although perhaps I read that incorrectly), in case that info helps anyone else wondering how to solve the common CS pin.

If anyone else has the standard Arduino Ethernet Shield (R3 version) shield working with Moteino and RFM69, please post how it was done, as from searching this forum, there are 4 or 5 other moteinites interested, perhaps more.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Ethernet shield and CS Pin 10
« Reply #3 on: July 28, 2014, 12:56:11 PM »
Actually the D10 trace is hard to get to once you soldered the side headers, even without them you have to be careful. You can see it on the transceiver side going to the D10 pin. It is actually easier to cut that trace on the transceiver itself. It is the last pad that is soldered to the Moteino on the same side as the antenna pin. It is right next to the OSHW logo. Cut that trace on the transceiver PCB then rewire it to another free pin. Check available pins at moteino.com/#pinout

scott216

  • Newbie
  • *
  • Posts: 41
Re: Ethernet shield and CS Pin 10
« Reply #4 on: July 28, 2014, 04:28:40 PM »
I solved my problem by using a modified Ethernet library that lets you define the slave select pin. So for my Ethernet module, I'm using pin D8.   

I think cutting the trace on D10 and trying to connect the slave select signal on the radio to another pin would be pretty hard.  It would be nice if future versions of Moteino let you choose between two pins with a solder jumper.  I don't know why everyone wants to use D10 for slave select.  Panstamp (similar to Moteino) does the same thing.

Antony

  • Newbie
  • *
  • Posts: 8
Re: Ethernet shield and CS Pin 10
« Reply #5 on: July 28, 2014, 04:39:42 PM »
That's great that you used a modified Ethernet library; can you post the mod or a link to the library, or to a thread that explains how to modify the standard ethernet library?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Ethernet shield and CS Pin 10
« Reply #6 on: July 28, 2014, 04:57:42 PM »
I solved my problem by using a modified Ethernet library that lets you define the slave select pin. So for my Ethernet module, I'm using pin D8.   

I think cutting the trace on D10 and trying to connect the slave select signal on the radio to another pin would be pretty hard.  It would be nice if future versions of Moteino let you choose between two pins with a solder jumper.  I don't know why everyone wants to use D10 for slave select.  Panstamp (similar to Moteino) does the same thing.

D10 is the SS pin on the mega328 so it's a natural choice for the first/main SPI device. If you use other SPI devices then the respective libraries should allow changing the CS line for their devices. The Moteino already allows this. There isn't much room left to add a jumper on the Moteino. Then the debate which digital pin it's going to be ... then dealing with those who didn't want that choice but something else for their own reasons. I think if you ask the same question the guys who made the Ethernet shield you will likely get a similar answer. It's much easier to deal with firmware than it is with hardware.

scott216

  • Newbie
  • *
  • Posts: 41
Re: Ethernet shield and CS Pin 10
« Reply #7 on: July 29, 2014, 08:48:55 AM »
D10 is the SS pin on the mega328 so it's a natural choice for the first/main SPI device. If you use other SPI devices then the respective libraries should allow changing the CS line for their devices. The Moteino already allows this. There isn't much room left to add a jumper on the Moteino. Then the debate which digital pin it's going to be ... then dealing with those who didn't want that choice but something else for their own reasons. I think if you ask the same question the guys who made the Ethernet shield you will likely get a similar answer. It's much easier to deal with firmware than it is with hardware.

Makes sense. 

A bit off topic: I just found out the hard way I can't use D2 because it's used by the transceiver. Not a big deal, I just changed my program to use D3.  But why is D2 even an available pin if it can't be used?  I did a simple test sketch that didn't even use the radio and it wouldn't control D2. 

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Ethernet shield and CS Pin 10
« Reply #8 on: July 29, 2014, 09:04:01 AM »
A bit off topic: I just found out the hard way I can't use D2 because it's used by the transceiver. Not a big deal, I just changed my program to use D3.  But why is D2 even an available pin if it can't be used?  I did a simple test sketch that didn't even use the radio and it wouldn't control D2.
It's because all the pins are available when you get the Moteino without a transceiver. A lot of people buy bare Moteinos for other purposes.

scott216

  • Newbie
  • *
  • Posts: 41
Re: Ethernet shield and CS Pin 10
« Reply #9 on: July 29, 2014, 09:20:32 AM »
A bit off topic: I just found out the hard way I can't use D2 because it's used by the transceiver. Not a big deal, I just changed my program to use D3.  But why is D2 even an available pin if it can't be used?  I did a simple test sketch that didn't even use the radio and it wouldn't control D2.
It's because all the pins are available when you get the Moteino without a transceiver. A lot of people buy bare Moteinos for other purposes.

Oh.  I didn't even know it was sold that way.

Antony

  • Newbie
  • *
  • Posts: 8
Re: Ethernet shield and CS Pin 10
« Reply #10 on: September 06, 2014, 06:14:58 PM »
For those messing around trying to interconnect their moteinos with leonardo/yśn, you may want to attach an RFM69 module to the leonardo/yśn so it can act as a gateway to your other moteinos. Below is some info and a header mod to the rfm69.h library which may be helpful (mod code is in bold).

The mod is necessary as the INT0 pin for these boards is different. I found it here: http://arduino.cc/en/Reference/attachInterrupt

Also, you must use the ICSP header (unlike other boards, not shared with any pinouts). Careful not to use the ICSP VOO which is 5v. Instead, use the 3.3v on the header of the main board to match the rfm69 VIN and TTL.

Choose a slave select pin as the ICSP header doesn't have a CS pin, nor will you find it on any header. The chip schematic does show a CS on pin8 but it's used to drive the RX led.

As Felix suggests elsewhere, after you've chosen your CS pin, don't forget to set RFM69::setCS(byte newSPISlaveSelect).

I also think there should be some sort of delay on sketch start up:  as a workaround, I found I had to disconnect my rfm69, upload the sketch, then reconnect it otherwise the microcontroller is not accessible (I guess the SPI device begins before the microcontroller).

Happy Moteino-ing, and hope this mod helps...

RFM69.h
// INT0 on AVRs should be connected to RFM69's DIO0 (ex on Atmega328 it's D2, on Atmega644/1284 it's D2)
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          2
#elif defined(__AVR_ATmega32U4__)
  #define RF69_IRQ_PIN      3
  #define RF69_IRQ_NUM      0

#endif
« Last Edit: September 09, 2014, 04:17:38 PM by Antony »