遇到奇怪的问题
本帖最后由 万马奔腾 于 2013-9-2 22:57 编辑同一个程序,以前测试成功的,现更换了板子就运行不了,是什么原因啊 ,有人遇到过吗?
是关于 PRO MINI+SD模块的 用SD库自带的程序运行可以的, 但是使用simpleSDAuido里面的程序就出现SD卡初始化失败啊 SD卡是3.3V电平。。PRO mini是5V如果中间没有可靠的电平转换。。有时可以用有时不能用是很正常的 弘毅 发表于 2013-9-2 22:16 static/image/common/back.gif
SD卡是3.3V电平。。PRO mini是5V如果中间没有可靠的电平转换。。有时可以用有时不能用是很正常的/*
SD card test
This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
Pin 4 used here for consistency with other Arduino examples
created28 Mar 2011
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
*/
// include the SD library:
#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) {
}以上代码可以正常执行的,说明操作SD卡模块是可以的
本帖最后由 万马奔腾 于 2013-9-2 22:40 编辑
万马奔腾 发表于 2013-9-2 22:36 static/image/common/back.gif
以上代码可以正常执行的,说明操作SD卡模块是可以的/*
Simple SD Audio example, shows the usage of most functions
via terminal at serial communication port.
This example shows how to use the SimpleSDAudio library for audio playback.
You need:
- An Arduino with ATmega168/ATmega368 or better
- An SD-Card connected to Arduinos SPI port (many shields will do)
-> copy some converted audio files on freshly formated SD card into root folder
- A passive loudspeaker and resistor or better: active speakers (then stereo output will be possible)
Audio signal output is at the following pin:
- Arduino with ATmega168/328 (many non-mega Arduinos): Pin 9
- Arduino with ATmega1280/2560 (many mega Arduinos) : Pin 44
Using passive speaker:
Audio-Pin --- -- ---- Speaker ---- GND
Using amplifier / active speaker / line-in etc.:
Audio-Pin --||------------------+-------- GND
100nF capacitor to amp
See SimpleSDAudio.h or our website for more information:
http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio
created29 Jun 2012 by Lutz Lisseck
*/
#include <SimpleSDAudio.h>
// Callback target, prints output to serial
void DirCallback(char *buf) {
Serial.println(buf);
}
char AudioFileName;
// Create static buffer
#define BIGBUFSIZE (2*512) // bigger than 2*512 is often only possible on Arduino megas!
uint8_t bigbuf;
// helper function to determine free ram at runtime
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
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(F("Free Ram: "));
Serial.println(freeRam());
// Setting the buffer manually for more flexibility
SdPlay.setWorkBuffer(bigbuf, BIGBUFSIZE);
Serial.print(F("\nInitializing SimpleSDAudio V" SSDA_VERSIONSTRING " ..."));
// If your SD card CS-Pin is not at Pin 4, enable and adapt the following line:
//SdPlay.setSDCSPin(10);
// Select between SSDA_MODE_FULLRATE or SSDA_MODE_HALFRATE (62.5kHz or 31.25kHz)
// and the output modes SSDA_MODE_MONO_BRIDGE, SSDA_MODE_MONO or SSDA_MODE_STEREO
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO)) {
Serial.println(F("initialization failed. Things to check:"));
Serial.println(F("* is a card is inserted?"));
Serial.println(F("* Is your wiring correct?"));
Serial.println(F("* maybe you need to change the chipSelect pin to match your shield or module?"));
Serial.print(F("Error code: "));
Serial.println(SdPlay.getLastError());
while(1);
} else {
Serial.println(F("Wiring is correct and a card is present."));
}
}
void loop(void) {
uint8_t count=0, c, flag;
Serial.println(F("Files on card:"));
SdPlay.dir(&DirCallback);
ReEnter:
count = 0;
Serial.println(F("\r\nEnter filename (send newline after input):"));
do {
while(!Serial.available()) ;
c = Serial.read();
if(c > ' ') AudioFileName = c;
} while((c != 0x0d) && (c != 0x0a) && (count < 14));
AudioFileName = 0;
Serial.print(F("Looking for file... "));
if(!SdPlay.setFile(AudioFileName)) {
Serial.println(F(" not found on card! Error code: "));
Serial.println(SdPlay.getLastError());
goto ReEnter;
} else {
Serial.println(F("found."));
}
Serial.println(F("Press s for stop, p for play, h for pause, f to select new file, d for deinit, v to view status."));
flag = 1;
while(flag) {
SdPlay.worker();
if(Serial.available()) {
c = Serial.read();
switch(c) {
case 's':
SdPlay.stop();
Serial.println(F("Stopped."));
break;
case 'p':
SdPlay.play();
Serial.println(F("Play."));
break;
case 'h':
SdPlay.pause();
Serial.println(F("Pause."));
break;
case 'd':
SdPlay.deInit();
Serial.println(F("SdPlay deinitialized. You can now safely remove card. System halted."));
while(1) ;
break;
case 'f':
flag = 0;
break;
case 'v':
Serial.print(F("Status: isStopped="));
Serial.print(SdPlay.isStopped());
Serial.print(F(", isPlaying="));
Serial.print(SdPlay.isPlaying());
Serial.print(F(", isPaused="));
Serial.print(SdPlay.isPaused());
Serial.print(F(", isUnderrunOccured="));
Serial.print(SdPlay.isUnderrunOccured());
Serial.print(F(", getLastError="));
Serial.println(SdPlay.getLastError());
Serial.print(F("Free RAM: "));
Serial.println(freeRam());
break;
}
}
}
}但是这段代码采用同样的接线,就出现错误了 串口输出("initialization failed. Things to check
如果是操作电平的问题,楼上代码串口输出也会出现错误啊~ 万马奔腾 发表于 2013-9-2 22:38 static/image/common/back.gif
但是这段代码采用同样的接线,就出现错误了 串口输出("initialization failed. Things to check
如果是 ...
{:soso_e103:} 这就好奇怪了
页:
[1]