Ethernet.begin() upsets state of Pin D13

Status
Not open for further replies.

grease_lighting

Well-known member
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() {

}
 
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.
 
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).
 
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.
 
Status
Not open for further replies.
Back
Top