Moteino & W5100 ethernet SPI support / SPI_HAS_TRANSACTION

Started by kiwisincebirth, January 07, 2015, 06:47:30 AM

bborncr

Hello everyone, I'm interested in creating a W5100 + Moteino gateway. I've been reading through this post and am confused regarding the exact status.  Which is the repository I should be using to try this out?

Regards,

TomWS

Quote from: bborncr on March 10, 2015, 12:34:32 PM
Hello everyone, I'm interested in creating a W5100 + Moteino gateway. I've been reading through this post and am confused regarding the exact status.  Which is the repository I should be using to try this out?

Regards,
Kiwi will have to advise you on the specifics on using the W5100 as I'm pretty sure he's using it in his Moteino Gateway.

Re: SPI transaction updates to the RFM69 library, the latest code is on Kiwi's github (referenced in an earlier post) and I am going to create a new extension to my 'virtualized' update to RFM69, which will add Kiwi's SPI Transaction updates in a derived class.  I'm hoping to have that posted on my github later this week (however it is 'March Madness'..., so any predictions at this point are entirely unreliable  ;)

I suspect that Felix is not ready to incorporate the SPI transaction change into the base class simply due to the amount of regression testing he would need to do, but I'll let Felix comment on that.  Also, the urgency is diminished if I'm able to get the SPI Transaction extension completed in a timely manner.

From your perspective, you can use Kiwi's change now (it works well and plays nice with W5100 and SD card libraries), or, when I finish the SPI Transaction extension, use that coupled with my virtualization update to RFM69.  AND, if you're not using Arduino IDE 1.6.0 (or 1.5.8  ) - you don't need any of this!!!

Tom

bborncr

What I understood is stopping the RF69 and Ethernet libraries from working together happily is that they are both using pin 10 as SS.  The fix would be to physically move the RF69 SS pin to another (9). And then change the SS using the line that I believe Felix posted previously. I would use 1.0.6 if 1.6.0 is causing problems.

Am I understanding this correctly or missing something vital? I have searched the forum but haven't found mention of an Ethernet/Moteino Gateway apart from this thread.

Regards,

TomWS

#48
Quote from: bborncr on March 11, 2015, 05:52:42 PM
What I understood is stopping the RF69 and Ethernet libraries from working together happily is that they are both using pin 10 as SS.  The fix would be to physically move the RF69 SS pin to another (9). And then change the SS using the line that I believe Felix posted previously. I would use 1.0.6 if 1.6.0 is causing problems.

Am I understanding this correctly or missing something vital? I have searched the forum but haven't found mention of an Ethernet/Moteino Gateway apart from this thread.

Regards,
I believe that the SS pin for the W5100 can be moved to virtually any pin.  Where it can't be moved is on an Arduino shield THAT IS plugged directly into an Arduino, but that's not an issue with Moteino - the Arduino shield will not plug directly into a Moteino board.  Consequently, whether you use the shield or a W5100 breakout board or design your own PCB, you can connect a different pin from the Moteino to the W5100 - this is a HARDWARE statement. 

Unfortunately the library is another story.  As far as I've seen, it's pretty unfriendly about operating with flexible parameters  AND I just did a deeper look into the library and see that it's even more obnoxious than I realized.  They hard code the SS bit into inline code - incredibly stupid - unless you want it to ONLY work with that limited configuration.  So, Net:  I need to get with my buddy Kiwi and see what he did.
Tom

kiwisincebirth

Hi there, in summary, since I lost my more detailed posting.

1. Use arduino 1.6.0, it contains the SpI transaction support to allow the two devices to play nice together.

2. Use the enhanced rfm69 library on my GitHub account, this adds the spi transaction support to the library.

3. I choose to change the Ethernet SS Pin, this requires a change to the Ethernet library, I published the change here. https://github.com/kiwisincebirth/Arduino/tree/master/Ethernet

Lastly, the Ethernet shield is 3.3v compatable, but does require 5v input power. In my setup I have a moteino mounted to a prototype shied which then has an Ethernet shield mounted to it. This means I am free to route any pin I want to pin 10 on the connector, to drive the Ethernet shield

I have been running my gateway without issue for well over a month now, the good thing is that I don't have worry about shutting it down correctly (like rasp pi) there is no OS or sd card to cause an issue.

Kiwi

bborncr

Thanks for the info.  I'll give those try.  I have a W5100 module that supposedly works at 3.3V for Vcc and logic. I also want a clean simple gateway that posts to my EMON server in the cloud.

Regards,

bborncr

I installed the KiwiSinceBirth RFM69 library and the w5100 files in "arduino-1.6.0/libraries/Ethernet/src/utility/". It turns out the module requires 5V Vcc so I took care of that. The PWR, LNK, SPD, FDS leds all come on and the TX/RX flashes as it sees network traffic. SS is pin 8. The code being used is the DHCP example code (also tried static but no change). Eventually, it times out and the Failed to Configure Ethernet message appears.  Below is the exact code (ethernet only to rules out any conflicts).  Any thoughts?

Connections Module --> Moteino

NSS --> 8
SCK --> 13
MI -->  11(MO)
MO --> 12 (MI)
RST --> not connected

/*
  DHCP-based IP printer

 This sketch uses the DHCP extensions to the Ethernet library
 to get an IP address via DHCP and print the address obtained.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 12 April 2011
 modified 9 Apr 2012
 by Tom Igoe

 */

#include <SPI.h>
#include <Ethernet.h>
#include <utility/w5100.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x33
};

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  W5100.select(8);
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
Serial.println("Ready....");
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
}

void loop() {

}

TomWS

I think you will find that the flash memory chip uses pin 8 as its CS...  If you don't have flash installed then there might not be a conflict unless the pin is getting inadvertently configured (via flash.initialize or something like that).

Check out the great image of the Moteino and its pinouts at: https://lowpowerlab.com/moteino/#pinout  Note the pins with asterisks.

I've downloaded this image and have it on my Desktop, referencing it quite often.  I think Felix should make this into a product, high quality image double laminated in plastic!

Tom

kiwisincebirth

You also need to add a couple of lines of code to set pin 10 as output, and set the output to low, otherwise the pin is a floating input pin, which could cause the rfm radio to interfere on the spi bus.

TomWS

Quote from: kiwisincebirth on March 13, 2015, 05:30:09 AM
You also need to add a couple of lines of code to set pin 10 as output, and set the output to low, otherwise the pin is a floating input pin, which could cause the rfm radio to interfere on the spi bus.
Good catch, Kiwi, I failed to see that, with the radio not use, pin 10 won't be declared as an output and SPI won't work, however, to disable the RFM69 CS, pin 10 should be HIGH, not LOW - easy typo.

Tom

bborncr

Thanks KiwiSinceBirth and TomWS!  It's all working.  The gateway is receiving sensor values and forwarding them via ethernet. The SS is on pin 7.

TomWS

Quote from: bborncr on March 13, 2015, 03:59:59 PM
Thanks KiwiSinceBirth and TomWS!  It's all working.  The gateway is receiving sensor values and forwarding them via ethernet. The SS is on pin 7.
GREAT! Thanks for sticking with it!  Glad its working for you!

Tom

kiwisincebirth

Quote from: TomWS on March 13, 2015, 08:45:13 AMGood catch, Kiwi, I failed to see that, with the radio not use, pin 10 won't be declared as an output and SPI won't work, however, to disable the RFM69 CS, pin 10 should be HIGH, not LOW - easy typo.

Tom
Yes when I wrote that (on train) I wasn't quite sure. bborncr, Glad it is working

bborncr

I have been having trouble with the Ethernet module not connecting.  Sometimes it worked and sometimes it didn't. After several days of frustration I think I found the problem and a solution.  According to many users the WIZNET module can have troubles after a cold start.  The fix has been to place a 220nF cap between RESET and GND.  I just performed a dozen resets without issue.  The suggested value for the cap is 100nF but I had the 220nF so I used it instead.

TomWS

Quote from: bborncr on March 17, 2015, 01:27:11 PM
I have been having trouble with the Ethernet module not connecting.  Sometimes it worked and sometimes it didn't. After several days of frustration I think I found the problem and a solution.  According to many users the WIZNET module can have troubles after a cold start.  The fix has been to place a 220nF cap between RESET and GND.  I just performed a dozen resets without issue.  The suggested value for the cap is 100nF but I had the 220nF so I used it instead.
Good to know!  Thanks for the tip!

Tom