【问题标题】:Card failed or not presented Arduino Mega卡失败或未提供 Arduino Mega
【发布时间】:2023-04-03 15:05:01
【问题描述】:

我正在尝试读取数据并将数据写入 SD 卡,但在代码开始时,我收到错误 Card Failed or not present。我更改了为 Arduino Uno 编写的示例代码中的引脚,但仍然给出相同的错误。我正在使用 Arduino Mega 2560。我该如何解决这个问题?我的代码在这里:

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 53;

void setup()
{
 Serial.begin(9600);
 Serial.print("Initializing SD card...");
 // make sure that the default chip select pin is set to
 // output, even if you don't use it:
 pinMode(53, OUTPUT);

 // see if the card is present and can be initialized:
 if (!SD.begin(chipSelect)) {
 Serial.println("Card failed, or not present");
 // don't do anything more:
 return;
 }
 Serial.println("card initialized.");
 }

 void loop()
 {

 }

【问题讨论】:

    标签: arduino sd-card


    【解决方案1】:

    请添加:

    digitalWrite(53, HIGH);
    

    如果它很低,Wiznet 芯片会破坏 SPI 总线。 (More details)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多