Using SD and Wiz850io with specific CS pins

Status
Not open for further replies.
Hello,
The following program hangs. It first detects the SDcard, the starts the network, but then as soon as I do anything with SD, it hangs. The only difference between my schematic and the WIZ820io & Micro SD Card Adaptor, is that I am using pin 3 and 4 as CS pins and toggling the reset pin in code. I really dont know how to debug this any further.

Code:
// All the pins
#define RX1_PIN 0
#define TX1_PIN 1
#define DATA_1_PIN  2
#define SDCARD_CS_PIN 3
#define WIZNET_CS_PIN 4
#define DATA_8_PIN  5
#define DATA_5_PIN  6
#define DATA_3_PIN  7
#define DATA_4_PIN  8
#define RX2_PIN 9
#define TX2_PIN 10
#define SPI_DOUT_PIN 11
#define SPI_DIN_PIN 12

#define SPI_CLK_PIN 13
#define DATA_2_PIN 14
#define POT1_PIN 15
#define POT2_PIN 16
#define BUTTON_PIN 17
#define I2C_SDA_PIN 18
#define I2C_SCL_PIN 19
#define DATA_6_PIN 20
#define DATA_7_PIN 21
#define STATUS_LED_PIN 22
#define WIZNET_RESET_PIN 23

#include "SPI.h"
#include "Ethernet.h"
#include "TeensyID.h"
#include "SD.h"


uint8_t mac[6];

void setup(){
    Serial.begin(115200);
    delay(100);
    Serial.println("hi");
    pinMode(STATUS_LED_PIN, OUTPUT);

    pinMode(WIZNET_RESET_PIN, OUTPUT);
    digitalWrite(WIZNET_RESET_PIN, LOW);    // begin reset the WIZ820io

    pinMode(WIZNET_CS_PIN, OUTPUT);
    digitalWrite(WIZNET_CS_PIN, HIGH);  // de-select WIZ820io

    pinMode(SDCARD_CS_PIN, OUTPUT);
    digitalWrite(SDCARD_CS_PIN, HIGH);   // de-select the SD Card
    digitalWrite(WIZNET_RESET_PIN, HIGH);
    digitalWrite(WIZNET_CS_PIN, LOW);

    if(SD.begin(SDCARD_CS_PIN)){
        Serial.println("sd detected");
    }
    else {
        Serial.println("no SD");
    }

    Ethernet.init(WIZNET_CS_PIN);
    IPAddress ipAddress;
    ipAddress.fromString("10.0.0.42");
    teensyMAC(mac);
    Ethernet.begin(mac, ipAddress);

    // this line will make it crash
    File _file = SD.open("config.jso", FILE_READ);
}

void loop(){
    digitalWrite(STATUS_LED_PIN, millis()%200 < 20);

}
 
After cutting some traces and changing the CS pins to the same as the WIZ820io & Micro SD Card Adaptor, it works!
So there is maybe a bug related to either the SD library or the Ethernet library. Where should I file this bug report?

Code:
// #define SDCARD_CS_PIN 3
// #define WIZNET_CS_PIN 4
#define SDCARD_CS_PIN 4
#define WIZNET_CS_PIN 10
 
There are several 'fast' CS/DC pins that some display drivers use. I believe the ethernet driver also uses them. These 'fast' pins are implemented in hardware and are used by the DMA hardware. If your driver uses DMA, it probably needs to use these pins. Several of the pins connect to the same hardware interface, so you can't use both of them for CS/DC pins at the same time.

The pins for 3.2/3.5/3.6 are:
  • Pin 9 (or alternatively pin 6);
  • Pin 10 (or alternatively pin 2);
  • Pin 15/A1;
  • Pin 20/A6 (or alternatively pin 23/A9);
  • Pin 21/A7 (or alternatively pin 22/A8).

If a device needs a fast CS (chip select) pin, and also needs a DC (data/command) pin, the DC pin typically also needs to be from the fast pin set.

Note, the alternatives are for the 3.2. I'm not sure whether the 3.5/3.6 supports all of the alternatives (I can verify that the 3.5 supports the alternate pin 6 as a fast pin). The Teensy LC does not have any fast SPI CS/DC pins.

See https://forum.pjrc.com/threads/33014-SPI-Chip-Selects-(Teensy-3-1-vs-3-2)?p=96072#post96072 for more details (in particular, Paul's response on 02-10-2016).
 
#define WIZNET_CS_PIN 4

On Teensy 3.x, the Ethernet library is using the SPI FIFO and hardware CS control, so it really wants you to only use the CS pins shown on the reference card.

So on Teensy 3.2, use pin 9, 10, 15, 20 or 21 for CS (as shown on the pinout reference). Pin 4 isn't supported for hardware CS.

card7a_rev1.png


The SD library accesses the card's CS as ordinary digital I/O, so any digital pin works for the SD card CS signal.
 
Status
Not open for further replies.
Back
Top