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

Thread: Ethernet.begin() upsets state of Pin D13

  1. #1
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    168

    Ethernet.begin() upsets state of Pin D13

    I'm making a battery powered project and am using pin D13 to turn it off via the touch screen. I find the when using Ethernet.begin, it interferes with the state of pin D13, causing it to go low. I've re-assigned the SCK pin to pin #14. Short of re-assigning a bunch of pins does anyone know what is causing this?


    Code:
      #include <SPI.h>
      #include "T3Mac.h"                      //  Use Teensy MAC address as Ethernet MAC address  data in mac[x]
      #include <Ethernet.h>  
    
      #define PWRoff 13       //  power off (by Teensy) control pin.    LOW == off    Otherwise HIGH
      #define ethRst 9        //  WIZ820/850 reset pin  (#9)
      #define ethCs 10        //  WIZ820/850 CS pin (D10, -1 to inhibit)   // if unit is present, it must be initialized
    
      IPAddress ip(192, 168, 103, 177);     //  IP of teensy
    
    void setup() {
          pinMode(PWRoff, OUTPUT);
          digitalWrite(PWRoff, HIGH);
          SPI.setSCK(14);       //  use alternate pin for SCK-0
          SPI.begin();
          delay(5000);
          Ethernet.begin(mac, ip);
    }
    
    void loop() {
    
    }

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,663
    I assume a T3.x? As 14 is not a SCK pin on T4.x.

    I did a quick look at ethernet library and did not find anywhere it did stuff with the SPI pins... But I might have missed it.

  3. #3
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    168
    Ooops, My bad. Yes it is a Teensy 3.2 that I'm using.

  4. #4
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    168
    This morning I tried setting the PCR lock bit for D13. The state of D13 did not change after Ethernet.begin() occurred. This shows something is trying to change the pin state. Of course I need D13 to be steady HIGH at power on then go low to turn off power. Guess I'll have to delayer the onion of the Ethernet routine(s).

  5. #5
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    168
    Digging into this some more, I find that in file <spi_drv.cpp> it defines all the SPI related pins (11, 12, 13) plus some default pins (7, 9, and 10) and assigns them starting state levels. Of course I also do not understand how or when the command <SPI.setsck(14)> modulates those settings. I'm also sort of surprised this problem did not show up in the SD-card initialization routine I perform before the ethernet initialization in the original program.

Posting Permissions

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