求助,为什么我使用SD卡扩展模块使用不了?
求助,为什么我使用SD卡扩展模块使用不了?求指教,在网上买了个SD卡读写模块 ,插到板子上后还是读不出SD卡,使用的是arduino的库文件SD中的例子,板子的型号是Ocrobot Mango 是 一款兼容arduino uno的板子,然后SD卡模块是使用的SD Card Shield V1.0 09/17/2013 。他上面带有电平转换模块
不知道是否是还需要修改?请大神们指教一下,我已经被快奔溃了 提问的好习惯是详细描述问题 而不是“用不了”“读写不了”之类模糊的词汇来描述
代码如果方便最好是贴出来的 别人也好找问题
还有就是环境 比如哪些模块
另外就是 SD卡的格式也要注意 单片机支持的应该是FAT 而FAT32支持就差了 如果格式成NTFS 。。。你懂的
错误也要说清楚 比如代码出错?还是有什么反应(要具体 比如编译就出错?或者是读取文件失败?或者是反馈值错误?等等)?
出错是学习最好的方式,出现问题 自己想法子添加DEBUG代码 一步一步找问题。
添加了DEBUG代码这样别人也好帮你找问题。 darkorigin 发表于 2014-9-29 00:14 static/image/common/back.gif
提问的好习惯是详细描述问题 而不是“用不了”“读写不了”之类模糊的词汇来描述
代码如果方便最好是贴出来 ...
这个我使用代码就是
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
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
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
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");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}
这个代码是使用的 arduino-1.0.5-r2\libraries\SD\examples\CardInfo中的例子,是使用的SD卡的库的例子。。格式我使用过FAT 和FAT32 两种格式都使用过。SD模块就是上面说的SD Card Shield V1.0 09/17/2013。 主板是Ocrobot Mango .。采用这个例子读写的时候 串口监视窗口的信息为
initialization failed. Things to check:
is a card is inserted?
Is your wiring correct?
did you change the chipSelect pin to match your shield or module?
根据翻译之后,进行修改过chipSelect 可以还是不行。至于连接,那个模块和主板是直接插上的,端口排序以及位置都和主板相同。 initialization failed. Things to check:
初始化失败,请检查:
is a card is inserted?
SD卡是否插入?
Is your wiring correct?
线路是否正确?
did you change the chipSelect pin to match your shield or module?
是否变更了片选信号到你的模块?
试试换个卡?
还有就是片选口是否正确要问下卖家。 你代码里面是4号口
还不行 最好就尝试换个ARDUINO试试
再不行那就是模块问题。
本帖最后由 沧海笑1122 于 2014-9-29 12:48 编辑
cyf211 发表于 2014-9-29 01:31 static/image/common/back.gif
这个我使用代码就是
#include
1、你需要描述一下你的接线(从你的描述看是叠装的,你需要和SD模块的店家确认一下具体接线),从你的SD模块照片看,片选口用的是D4(CS connect to D4)。
2、看到你的卡是128M的,应该是早先的老卡,建议你换个2G的卡试试,格式为FAT
3、没有看到你的SD模块上的电平转换开关,应该和UNO的电平一致,比如都用5V。你这款芒果的电平我不知能否设置,我用过恩孚的UNO,电平是可以设置的(3.3V或者5V)。电平原则就是确保两边的电平一致即可(可以用万用表确认一下)。
4、对于初学者来说,调试往往就是“换”。比如换一块UNO试试,这种试验的接线都比较简单,SD卡也不是能耗高的设备,所以要有信心。说到UNO,就是一低值易耗品,你应该多备几块。arduino的定位还是电子玩具,百十元的东西也要有思想准备不可能百年大计,建议买品牌的是出于初学者少走弯路。
希望能够帮到你,祝你好运。 可能是接触不好!! 不知道你解决了吗?堆叠设计应该接触不会有问题。
1、卡问题,换卡
2、如果使用库例程,不要修改
我用那种小的SD模块测试通过无问题
页:
[1]