以太网屏蔽SD卡出现故障

时间:2013-08-14 17:22:06

标签: arduino sd-card

我买了一个Arduino以太网盾,我在使用SD卡上的文件的网络服务器时遇到了问题。在端口80上运行的服务器提供数据,但是当我加载它时,我似乎得到了像

这样的数据
  

文件·找不到

     

找不到文件

     

找不到文件

     

找不到文件

     

title>04NotÁFhund<šhtml|找不到文件

     

找不到文件

     

找不到文件

     

<” HTML> *文件“otfoundž/ p> žtitle> 404 Not F·und

或它开始下载类似的东西到上面(我假设标题像实际内容一样腐败)

如果我不使用SD卡而我只是提供写入草图的预先写好的网页,那么只要SD卡不在插槽中,页面就会正确显示。此外,SD库表示,当它存在时,它无法看到“index.html”

我在Arduino Uno上使用Transcend Micro SDHC 4GB(FAT32)和Ethernet Shield R3,我尝试格式化Micro SD卡。我的草图如下。

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 130); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

File webFile;

void setup()
{
  Ethernet.begin(mac, ip);  // initialize Ethernet device
  server.begin();           // start to listen for clients
  Serial.begin(9600);       // for debugging

  // initialize SD card
  Serial.println("Initializing SD card...");
  if (!SD.begin(4)) {
      Serial.println("ERROR - SD card initialization failed!");
      return;    // init failed
  }
  Serial.println("SUCCESS - SD card initialized.");
  // check for index.htm file
  if (!SD.exists("index.html")) {
      Serial.println("ERROR - Can't find index.html!");
  }      
  Serial.print("Running on ");
  Serial.println(Ethernet.localIP());
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    client.println("<html><head><title>404 Not Found</title></head><body><p>File not found</p></body></html>");
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

2 个答案:

答案 0 :(得分:0)

我对SD卡的体验是,从中读取它们比写入它们更稳定。因此,如果您的SDHC-USB转换器可以插入您的PC(并且存在许多供应商/型号),那么请在您的PC上格式化并初始化SD卡。

有一个名为SDFormatter V3.1的免费软件包可以很好地用FAT32格式化SDHC卡。在SD插槽中多次使用磁盘后,请不要相信磁盘已正确格式化。

使用8.3文件命名约定,并将文件格式化为FAT32设备。最后,将要传递的网页加载到SD卡的根目录中。

现在,将SD卡插入Arduino插槽并尝试从卡中读取。 NOT 在Arduino上初始化或格式化卡片。只需分配或启动SDHC设备并读取卡的根目录文件。

请发布您的测试程序。具有以太网功能的程序似乎没有正确“开始”SD卡。这就是为什么你应该在使以太网连接工作之前读取卡并将文件打印到显示器上(看起来像是这样,所以一旦你的文件测试程序工作就应该完成!)

使用FAT32格式的卡,编写一个测试程序,该程序将打开一个文件并将其内容写在Serial行上并返回到您的PC。在使用无线/以太网连接之前调试此功能。

答案 1 :(得分:0)

有两个问题需要注意:1)你的屏蔽没有修复5100芯片的错误,2)SPI总线要求两个设备的SS(从机选择)同时没有激活(低电平), SS = 5100的数字引脚10和SD = SD的数字引脚4(屏蔽中包含的引脚)。

相关问题