在arduino的SPI中使用以太网和SD卡



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

我怎样才能做到这一点?我从

下面的草图中得到以下输出
initialization done.
DONE Ethernet as well with IP: 255.255.255.255

SD卡初始化正确,但以太网未初始化。以太网、SD卡的CS我分别用了10、4引脚。

程序如下

#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
}

只需声明两个CS引脚作为输出。

最新更新