SPI.beginTransaction, how do I make it work with Ethernet shield?

I'm currently using Ehernet.h (will be moving to Ethernet2.h soon when the shield turns up).
I can't seem to change the SPI speed, I have a scope connected to the SPI clock, it stays at 4MHz.
The line of code I'm using is:

SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));

Obviously this is on a Due. No other devices on the SPI bus.
What have I missed? I tried setting 2MHz as well, no difference.

Whooooaaa, now you asking for trouble.... :stuck_out_tongue:

Ethernet causes a whole heap of problems if you want it to play nice with other stuff.........

Might I recommend you get the Wiznet 5500 library from Github...... I had most success with that! (Also where I was able to select a clock divider of 3) :wink:

G

I have ethernet2 installed, which I believe is for the 5500. Until the 5500 shield turns up, I want to see what the 5100 can do as I have it sat in front of me :slight_smile:
I don't need it to play nice with any other SPI devices :slight_smile:
It looks like the 4MHz SPI speed is coded into W5100.cpp, Is it possible to create a local copy in the sketch folder and modify it and have the compiler use that instead of the installed code? I don't want to edit the installed one in case I reinstall and lose the edit.

ghlawrence2000:
Might I recommend you get the Wiznet 5500 library from Github...... I had most success with that! (Also where I was able to select a clock divider of 3) :wink:

I've taken a look at this and it seems the SPI speed is hard coded in w5500.cpp, much like the 5100. Did you edit the library or is there some other method I can use to change the speed?

Yes, I just edited w5500.cpp :-

void W5500Class::init(void)
{
    delay(1000);

#if defined(ARDUINO_ARCH_AVR)
    initSS();
    SPI.begin();
#else
  SPI.begin(SPI_CS);
  // Set clock to 4Mhz (W5100 should support up to about 14Mhz)
//  SPI.setClockDivider(SPI_CS, 21);
//  SPI.setClockDivider(SPI_CS, 8); // 7 Mhz, ok  
  SPI.setClockDivider(SPI_CS, 3); // 14 Mhz, ok  
//  SPI.setClockDivider(SPI_CS, 3); // 28 Mhz, ok 
  //SPI.setClockDivider(SPI_CS, 2); // 42 Mhz, ok 
  SPI.setDataMode(SPI_CS, SPI_MODE0);
#endif
    for (int i=0; i<MAX_SOCK_NUM; i++) {
        uint8_t cntl_byte = (0x0C + (i<<5));
        write( 0x1E, cntl_byte, 2); //0x1E - Sn_RXBUF_SIZE
        write( 0x1F, cntl_byte, 2); //0x1F - Sn_TXBUF_SIZE
    }
}

Interesting, that looks quite different to the code in the library I have:

// SPI details
SPISettings wiznet_SPI_settings(800000, MSBFIRST, SPI_MODE0);
uint8_t SPI_CS;

void W5500Class::init(uint8_t ss_pin)
{
  SPI_CS = ss_pin;

  delay(1000);
  initSS();
  SPI.begin();

  for (int i=0; i<MAX_SOCK_NUM; i++) {
    uint8_t cntl_byte = (0x0C + (i<<5));
    write( 0x1E, cntl_byte, 2); //0x1E - Sn_RXBUF_SIZE
    write( 0x1F, cntl_byte, 2); //0x1F - Sn_TXBUF_SIZE
  }
}

It looks like I can just change the SPI settings, I can’t test until the 5500 shield arrives (might be today with any luck).
The 5100 Ethernet library has a similar setting:

#define SPI_ETHERNET_SETTINGS ETHERNET_SHIELD_SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0)

I tried to #include a local copy at the start of the sketch, but I couldn’t get it to use it, I really don’t like the idea of modifying the libraries directly, Is there no way to have local variants?
I guess I could copy all the required files to the sketch and modify all the #include statements to make it work, but this is a bit of a pain, assuming this would even work.

https://codeload.github.com/Wiznet/WIZ_Ethernet_Library/zip/master

This is the library I am using, and I don't understand the problem of modifying the library to be honest.

G

Unless I backup the arduino libraries, any changes I make will be lost if I reinstall. If I share a sketch with someone else, I'll also need to share my libraries, which might clash with any projects they have which use the same libraries. It just doesn't strike me as being sensible.
If the files are inside the sketch folder, that would be OK.

I'm still new to the arduino environment, which method of adding the library did you use? Add zip file?

Configuration of specific libraries within the library is common. It is not difficult to say 'change line x of file y to this', indeed that is what most people do.

Yes, I installed as zip.

G

When I selct "WIZ_Ethernet_Library-master.zip"
I get "Specified folder/zip file does not contain a valid library"
I get the same if I unzip it first and select the folder.

I can only assume this is a 1.6.12 related issue.

I have also got 1.7.11 from arduino.org
This version allows it to install, but when I click on the Wiz Ethernet library, all I get is a new blank line in the sketch.

Which IDE should I be using 1.6.12 from .cc or 1.7.11 from .org?

OOPs.... I told you wrong.

Extract the folder from the zip, then copy 'Ethernet' folder from 'Arduino IDE 1.5.x' to your libraries folder.

G

Ah, hehe, I'll give that a go.

Thanks for the help. I suspect my next questions will move to the networking section :slight_smile: