我是 Arduino 新手,我有一个以太网屏蔽,顶部有一个 SD 插座,但它似乎不起作用。我只是想运行一个从 SD 库示例中获取的简单草图以获取有关卡的信息,但是“card.init(SPI_HALF_SPEED,chipSelect)”部分总是失败。
我已将 ChipSelect 引脚设置为 4,并将引脚 10 设置为输出,仍然没有。
我的代码:
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT); // change this to 53 on a mega
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
}
void loop(void) {
}
我得到什么:
正在初始化 SD 卡...初始化失败。检查事项: * 是否插入了卡?* 你的接线正确吗?*您是否更改了芯片选择引脚以匹配您的屏蔽或模块?
我正在使用 Arduino Uno R3,Ethernet Shield(不是官方的)。我试过几张 SD 卡:SD/SDHC、2/4/16 Gb、Sandisk/Kingston,用 FAT16/FAT32 格式化
恐怕防护罩本身有些问题(尽管以太网部分正在工作)。如何确定问题的根源?请帮忙!