【问题标题】:Using Ethernet and SD card together in SPI of arduino在arduino的SPI中同时使用以太网和SD卡
【发布时间】:2015-07-31 09:18:14
【问题描述】:

我正在尝试在单个项目中使用以太网模块 ENC28J60 (http://www.amazon.com/ENC28J60-Ethernet-Network-Module-STM32/dp/B008B4QIV2) 和 SD 卡模块。我必须从网络中读取数据并将它们写入 micro sd 卡。

我怎样才能做到这一点?我正在通过下面的草图获得以下输出

initialization done.
DONE Ethernet as well with IP: 255.255.255.255

SD 卡已正确初始化,但以太网未正确初始化。 我已分别将针 10,4 用于以太网的 CS、SD 卡。

程序如下

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,200);
IPAddress gateway(192,168,1,99); 
IPAddress mask(255,255,255,0); 

//File myFile;
EthernetServer server(80);

void setup()
{
  Serial.begin(9600);
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }else {
   Serial.println("initialization done.");
  }

  Ethernet.begin(mac, ip,gateway,gateway,mask);
  server.begin();
  delay(5000);
  Serial.print("DONE Ethernet as well with IP: ");
  Serial.println(Ethernet.localIP());


}


void loop(){
  //todo

}

【问题讨论】:

    标签: arduino ethernet arduino-uno spi


    【解决方案1】:

    只需将两个 CS 引脚声明为输出即可。它会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多