极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14429|回复: 2

关于W5100和SD卡冲突的问题

[复制链接]
发表于 2016-4-24 22:18:39 | 显示全部楼层 |阅读模式
代码如下,W5100初始化成功后,在调用SD卡库就不能对卡进行操作了。
实地检测,如果在5100初始化成功后,把片选直接拉高,sd卡也不能进行操作。
5100芯片内部发生了什么

/*
  Web client

This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13

created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe, based on work by Adrian McEwen

*/

#include <SPI.h>
#include <Ethernet.h>
#include <SD.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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "185.119.255.57";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 199, 177);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

/*TF卡*/
File myFile;


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  pinMode(10, OUTPUT);
  digitalWrite(10,HIGH);
  pinMode(10, OUTPUT);
  digitalWrite(4,LOW);

  if (!SD.begin(4)) {
    Serial.println("init failed!");
    return;
  }



  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
  digitalWrite(10,INPUT);

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");

//    // Make a HTTP request:
   client.println("POST /disk/ HTTP/1.1\r");

    client.println("Accept: text/html, application/xhtml+xml, image/jxr, */*");

    client.println("Referer: http://185.119.255.57/disk/");

    client.println("Accept-Language: zh-CN");

    client.println("Content-Type: multipart/form-data; boundary=sosad");

    client.println("Origin: http: //185.119.255.57");

    client.println("Accept-Encoding: gzip, deflate");

    client.println("Host: 185.119.255.57");

    client.println("Content-Length: 613");

    client.println("Connection: Keep-Alive");

    client.println("Cache-Control: no-cache");

    client.print("\n");

    client.println("--sosad");

    client.println("Content-Disposition: form-data; name=\"username\"");

    client.println();

    client.println("surunbing");

    client.println("--sosad");

    client.println("Content-Disposition: form-dat; name=\"headImg\"; filename=\"test.txt\"");

    client.println("Content-Type: text/plain");

    client.println();



    myFile = SD.open("test.txt",FILE_READ);
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening");
  }

    client.println();
    client.println("--sosad--");   
    client.stop();

}
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  





}
回复

使用道具 举报

发表于 2016-4-24 23:42:51 | 显示全部楼层
用不同的片选引脚
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-4-25 00:01:04 | 显示全部楼层
davidce 发表于 2016-4-24 23:42
用不同的片选引脚

片选没有用
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 21:19 , Processed in 0.037061 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表