Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 17 of 17

Thread: Teensy MicroMod Ethernet on SPI1

  1. #1
    Junior Member
    Join Date
    Oct 2021
    Posts
    8

    Teensy MicroMod Ethernet on SPI1

    Hi,

    I am having an issue getting a WizNet850io to run on SPI1 on the MicroMod (SPI works fine on the MM and 4.0 - I have not yet soldered on pins to the back of the 4.0 to try SPI1). It spent a while yesterday poking around with a scope to verify the pins that and numbering that match SPI1 and that doesn't seem to be the problem:

    5500 on SPI

    Click image for larger version. 

Name:	SPI.png 
Views:	31 
Size:	82.6 KB 
ID:	26107

    5500 on SPI1

    Click image for larger version. 

Name:	SPI1.png 
Views:	37 
Size:	84.5 KB 
ID:	26108

    However, the code always fails at hardwareStatus == EthernetNoHardware for SPI1.

    I did follow the library updates suggested by Paul in Thread: Teensy 4.1 SPI1 on W5500 Ethernet module Communication Problem? and it certainly seems like bi-directional communications is happening with the chip. Am I missing something simple here? Is the SPI1 port capable of the settings being used?

    I'm currently testing on a SF ATP carrier board but this is going on a custom board I am designing and I need to figure out if this is possible before I route it to SPI1. I have several other chips running on SPI and would prefer to separate the Ethernet. (I also have an SD card socket fitted so SPI2 is potentially out - I have not tried ethernet there).

    Also, I'm fairly new to the teensy and started playing with the 4.0 a few months ago. The MicroMod form factor is great for my use case (very low volume light industrial) but the pin numbering changes have me a little confused. With the MM addition to teensyduino are the MM pin numbers correct or the 4.0. I have no hard examples in front of me but it seems like mostly the 4.0 numbers are correct but SF port names not so much? 4.0 SPI2 seems to be what SF calls SPI1/SD and SPI1 is kind of randomly spread around

    My current setup is:

    MOSI_1: MM pin 67 (G8) | 4.0 pin 26
    MISO_1: MM pin 19 (RX1 | 4.0 pin 0
    SCLK_1: MM pin 8 (G11) | 4.0 pin 27
    CS_1: MM pin 17 (TX1) | 4.0 pin 1

    I have updated utility\w5100.cpp, socket.cpp, Ethernet.cpp, and EthernetClient.cpp in \\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Ethern et\src to use SPI1 instead of SPI and am just using the example code below for testing.

    Code:
    #include <SPI.h>
    #include <Ethernet.h>
    #include <EthernetClient.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, 0x02 };
    uint8_t cmd_inventory[10] = { 0x02, 0x00, 0x09, 0xFF, 0xB0, 0x01, 0x00, 0x18, 0x43 };
    
    EthernetClient client;
    IPAddress server(192, 168, 0, 159);
    void setup() {
      // You can use Ethernet.init(pin) to configure the CS pin
      Ethernet.init(1);  // Most Arduino shields
     
      // Open serial communications and wait for port to open:
      Serial.begin(9600);
    
    
      // start the Ethernet connection:
      Serial.println("Initialize Ethernet with DHCP:");
      if (Ethernet.begin(mac) == 0) {
        Serial.println("Failed to configure Ethernet using DHCP");
        if (Ethernet.hardwareStatus() == EthernetNoHardware) {
          Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
        } else if (Ethernet.linkStatus() == LinkOFF) {
          Serial.println("Ethernet cable is not connected.");
        }
        // no point in carrying on, so do nothing forevermore:
        while (true) {
          delay(1);
        }
      }
      // print your local IP address:
      Serial.print("My IP address: ");
      Serial.println(Ethernet.localIP());
    
      // give the Ethernet shield a second to initialize:
      delay(1000);
      Serial.println("connecting...");
    
      // if you get a connection, report back via serial:
      if (client.connect(server, 10001)) {
          Serial.println("connected");
          Serial.println(Ethernet.localIP());
      }
      else {
          // if you didn't get a connection to the server:
          Serial.println("connection failed");
      }
    Thanks for any help available on this!

    Aaron

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,226
    Looks like there are 75 places in the library where SPI is referenced. Are you sure you edited all 75 from SPI to SPI1?

  3. #3
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    I did a find and replace in each file but i will verify the total count and make sure I got them all

    Thanks for the quick response.

  4. #4
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Notepad++ is claiming 103? (104th is the include in w5500.h)

    Search "SPI." (104 hits in 5 files of 16 searched)
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Ethern et\src\Ethernet.cpp (28 hits)
    Line 36: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 39: SPI.endTransaction();
    Line 46: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 50: SPI.endTransaction();
    Line 84: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 95: SPI.endTransaction();
    Line 137: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 141: SPI.endTransaction();
    Line 155: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 157: SPI.endTransaction();
    Line 163: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 165: SPI.endTransaction();
    Line 172: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 174: SPI.endTransaction();
    Line 181: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 183: SPI.endTransaction();
    Line 189: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 191: SPI.endTransaction();
    Line 196: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 199: SPI.endTransaction();
    Line 204: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 207: SPI.endTransaction();
    Line 212: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 215: SPI.endTransaction();
    Line 221: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 223: SPI.endTransaction();
    Line 228: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 230: SPI.endTransaction();
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Ethern et\src\EthernetClient.cpp (6 hits)
    Line 185: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 187: SPI.endTransaction();
    Line 197: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 199: SPI.endTransaction();
    Line 209: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 211: SPI.endTransaction();
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Ethern et\src\socket.cpp (41 hits)
    Line 74: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 98: SPI.endTransaction();
    Line 122: SPI.endTransaction();
    Line 138: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 162: SPI.endTransaction();
    Line 194: SPI.endTransaction();
    Line 201: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 203: SPI.endTransaction();
    Line 212: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 214: SPI.endTransaction();
    Line 222: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 224: SPI.endTransaction();
    Line 228: SPI.endTransaction();
    Line 238: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 242: SPI.endTransaction();
    Line 251: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 253: SPI.endTransaction();
    Line 308: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 345: SPI.endTransaction();
    Line 354: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 356: SPI.endTransaction();
    Line 369: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 372: SPI.endTransaction();
    Line 436: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 439: SPI.endTransaction();
    Line 448: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 456: SPI.endTransaction();
    Line 459: SPI.endTransaction();
    Line 461: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 465: SPI.endTransaction();
    Line 473: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 476: SPI.endTransaction();
    Line 487: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 495: SPI.endTransaction();
    Line 505: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 508: SPI.endTransaction();
    Line 514: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 522: SPI.endTransaction();
    Line 526: SPI.endTransaction();
    Line 528: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 533: SPI.endTransaction();
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Ethern et\src\utility\w5100.cpp (28 hits)
    Line 108: SPI.begin();
    Line 111: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 196: SPI.endTransaction();
    Line 199: SPI.endTransaction();
    Line 283: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 285: SPI.endTransaction();
    Line 289: SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    Line 291: SPI.endTransaction();
    Line 306: SPI.transfer(0xF0);
    Line 307: SPI.transfer(addr >> 8);
    Line 308: SPI.transfer(addr & 0xFF);
    Line 310: SPI.transfer(buf[i]);
    Line 319: SPI.transfer(cmd, 4);
    Line 321: SPI.transfer(buf, NULL, len);
    Line 325: SPI.transfer(buf[i]);
    Line 373: SPI.transfer(cmd, len + 3);
    Line 375: SPI.transfer(cmd, 3);
    Line 377: SPI.transfer(buf, NULL, len);
    Line 381: SPI.transfer(buf[i]);
    Line 398: SPI.transfer(0x0F);
    Line 399: SPI.transfer(addr >> 8);
    Line 400: SPI.transfer(addr & 0xFF);
    Line 402: buf[i] = SPI.transfer(0);
    Line 408: SPI.transfer(cmd, 4); // TODO: why doesn't this work?
    Line 420: SPI.transfer(cmd, 4);
    Line 422: SPI.transfer(buf, len);
    Line 464: SPI.transfer(cmd, 3);
    Line 466: SPI.transfer(buf, len);
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Ethern et\src\utility\w5100.h (1 hit)
    Line 18: #include <SPI.h>

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,226
    Ok, yes, edit all 103 places!

  6. #6
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    I checked it line by line against the list you had in the other thread and don't see any differences. I fixed the polarity on the scope recordings in the picture below so the decodes are closer to reality, it seems to be trying each of the three w5xxx chips as per the w5100 library, but I am still getting a no hardware found error with SPI1.

    Click image for larger version. 

Name:	RigolDS0.png 
Views:	27 
Size:	84.4 KB 
ID:	26118


    I did try setting the SPI1 pins directly above SPI1.begin on W5100.cpp:

    4.0 numbering
    CS set to 1
    SPI1.setMOSI(26);
    SPI1.setMISO(0);
    SPI1.setSCK(27);

    and
    MM numbering

    CS set to 17
    SPI1.setMOSI(67);
    SPI1.setMISO(19);
    SPI1.setSCK(8);


    both seemed to work?? so I am assuming this isn't doing anything (or you mapped both pin sets on the MM?)

    Anyway, I am going to continue working on this today, any suggestions are appreciated.

    Thanks

  7. #7
    i Have the same issues, but i cant rule out HW errors yet, but i am very curious how this progress, using the teensy micromod with the w5500 connected to SPI1, the same pins as atete.

    Include my schematic in case the actual error is there Click image for larger version. 

Name:	skeem.png 
Views:	21 
Size:	251.2 KB 
ID:	26968

  8. #8
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    We were short on time and rather than resolve this in software we just swapped the w5500 back to spi0 and moved our other devices to spi1

  9. #9
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Finally got back to playing with this. Just a quick update on this in case anyone else runs into issues with the MicroMod and SPI1. Turns out it was a simple issue of believing the SparkFun pinout...

    After moving the Ethernet to SPI0 and our other SPI devices to SPI1 we were still having issues with CS not working and just used another GPIO - then we noticed issues with MISO. After all that I looked at the SparkFun pinout and finally compared it to KurtE's spreadsheet and realized that TeensyPin 0 and 1 are reversed (MM 17 and 19), so when used as SPI1 your CS and MISO are reversed. There was much face palming going on when we realized that was all it was... A new board for the wall of shame and another project for PCBway! (and KurtE's spreadsheet is now taped to my wall; might have to get it blown up to poster size)

  10. #10
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,348
    Glad you have it working.

    @Paul @ateter - In cases like this, I really wish someone would instead of manually editing SPI. to SPI1. would instead update the class to somewhere pass in which SPI object to use. As more and more most processors are supporting
    multiple SPI ports and it is shame if each one has to manually edit like this...

    Like change the main begin to something like:
    Code:
    	static int begin(uint8_t *mac, unsigned long timeout = 60000, unsigned long responseTimeout = 4000, SPIClass &spi=SPI);
    Then have this begin save it away like:
    Code:
    _spi = &spi;
    where _spi is defined static either private/public/protected within the ethernet class and then change all of the users
    from SPI.xyz to _pspi->xyz.... or in some cases maybe EthernetClass::_pspi->xyz...

    I would try it, but I really don't use Ethernet on a teensy... Much more likely if it were WIFI but...

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,226
    Quote Originally Posted by KurtE View Post
    would instead update the class to somewhere pass in which SPI object to use. As more and more most processors are supporting multiple SPI ports and it is shame if each one has to manually edit like this...
    Added to my low priority list. Realistically, a lot of other software work is much higher priority than more features for Wiznet ethernet chips.

  12. #12
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,348
    Quote Originally Posted by PaulStoffregen View Post
    Added to my low priority list. Realistically, a lot of other software work is much higher priority than more features for Wiznet ethernet chips.
    I hacked up a version that builds, not sure if I have any hardware to test it...
    https://github.com/KurtE/Ethernet/tree/SPIx

  13. #13
    Quote Originally Posted by ateter View Post
    Finally got back to playing with this. Just a quick update on this in case anyone else runs into issues with the MicroMod and SPI1.
    ateter-I am also attempting to use SPI1 with the MM in my application. Besides moving the hardware lines to MM pins 67, 19, 8 17 and besides changing all the SPI references to SPI1 in the source library you were using, is there anything else you had to do in particular to get those pins in SPI1(3) mode? Or does the instantiation of SPI1 automatically do that for you? The alt pin assignment stuff is new to me.

  14. #14
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,348
    Note, I will try out some of the stuff in my WIP branch above in #12 in the next few days. I received an ethernet setup from Amazon... Which I should pickup in town probably tomorrow.

    But if anyone tries it out before me, that would be good as well.

  15. #15
    Senior Member Blackaddr's Avatar
    Join Date
    Mar 2017
    Location
    Canada
    Posts
    331
    Co-incidence this thread just got bumped. I have been having the week from hell with SPI1 in the MicroMOD. I designed a board for MicroMOD in the late Summer'21 based on the SparkFun schematics/datasheets. Couldn't' get SPI to work. Traced it to the using pins 68/70 on the MicroMOD being used for CS and MISO not working.

    My PCB was wrong because Sparkfun datasheets was wrong, however it appears a simple swap cannot solve the problem as neither of those pins appear to support MISO accoring to the i.MX RT1060 Reference manual. I've attached an image of the alternate pin functionality from Table 9-1 (Muxing Options). Note this is Rev1 of the datasheet. They're up to Rev3 but I don't have a copy to determine if this table is itself wrong.

    Click image for larger version. 

Name:	muxing.jpg 
Views:	4 
Size:	63.4 KB 
ID:	27814

    For SPI1 (a.k.a. LPSPI3), the MISO (a.k.a SIN) is only supported on balls GPIO_AD_B1_13 and GPIO_AD_B0_02. Pins 68/70 on the MicroMod connector are logical Teensy pins 38/39 and those are balls SD_B0_04, and SD_B0_05.

    GPIO_AD_B0_02 is Pin TX0/1 on the MicroMod/Teensy, which matches with the Teensy 4.1 pinout diagram for that logical pin.

    It appears that the only valid MISO pin for SPI1 on the Micromod is actually logical Teensy pin TX0/1, which is pin 17 on the MicroMod M.2. connector. I don't see GPIO_AD_B1_13 as an assigned ball on the Sparkfun schematic.

    I was able to get SPI1 working by fly-wiring from the pin 17 on my M.2 connector to MISO on my SPI chip.

    Can anyone confirm I'm not going crazy here, it looks like Teensy 4.1 and MicroMod do not support MISO on logical Teensy pin 39 based on the RT1060 Reference Manual.

    I should also note that after the 'pin swap fix' for pins 38/39 to Teensy cores in December, I can no longer get the DAT2 pin on my MicroMod ATP board to work at all with either logical pin 38 or 39 but it works fine before this update.
    Last edited by Blackaddr; 03-12-2022 at 01:26 PM.

  16. #16
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,348
    For what it is worth, I just issued a PR to allow you to specify which SPI port to use on the init method:

    Tested using my own Micromod breakout and I only tried with link status, but that worked on SPI, SPI1 and SPI2 on My micromod board.
    Talking to a HiLetGo board I purchased on Amazon...

    Click image for larger version. 

Name:	screenshot.jpg 
Views:	3 
Size:	90.7 KB 
ID:	27817

    I tried on pins:

    SPI pins (10, 11, 12, 13)
    Ethernet.init(10);
    Ethernet.init(10, SPI);

    SPI1 pins (10, 26, 1, 27)
    Ethernet.init(10, SPI1);

    SPI2 pins (10, 35, 34, 37)
    Ethernet.init(10, SPI2);

  17. #17
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    @KurtE - I just tested the above on a T_4.0 that I have on my desk at home (MMods have somehow all made it back to the office), seems to do the trick, ran the DHCP address printer and got an address.

    Everyone else, I retract my last post, the SF sheet is fine and apparently a swap of the pins dating back to when I had the Ethernet on SPI1 occurred and managed to survive several revs and swapping the devices attached to the port

    KurtE your doc did actually help find this, although maybe not as intended?
    Click image for larger version. 

Name:	Capture1.PNG 
Views:	3 
Size:	36.4 KB 
ID:	27824
    My late night "discovery" that the SF sheet was wrong; I was looking at your MM ATP and Machine Learning columns instead of serial. I think that you might have transposed the RX and TX for those two columns (Serial and everywhere else have it correct). Thank you for swapping those, it did the trick for finding the problem!

    Sorry for any confusion, all sheets appear to be correct (other than the MMATP and Machine Learning columns on the spreadsheet - unless I am still confused, which at this point is 100% possible).

    For the record - SPI1

    MOSI = MM p67 : T4 p26 : RT1062 pin G12 (AD_B1_14)
    MISO = MM p17 : T4 p1 : RT1062 pin M11 (AD_B0_02)
    SCK = MM p8 : T4 p27 : RT1062 pin J14 (AD_B1_15)
    CS = MM p19 : T4 p0 : RT1062 pin G11 (AD_B0_03)

    (I think .... maybe ... probably)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •