极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11503|回复: 4

遇到奇怪的问题

[复制链接]
发表于 2013-9-2 21:41:23 | 显示全部楼层 |阅读模式
本帖最后由 万马奔腾 于 2013-9-2 22:57 编辑

同一个程序,以前测试成功的,现更换了板子就运行不了,是什么原因啊 ,有人遇到过吗?
是关于 PRO MINI+SD模块的   用SD库自带的程序运行可以的, 但是使用simpleSDAuido里面的程序就出现SD卡初始化失败啊
回复

使用道具 举报

发表于 2013-9-2 22:16:00 | 显示全部楼层
SD卡是3.3V电平。。PRO mini是5V如果中间没有可靠的电平转换。。有时可以用有时不能用是很正常的
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-9-2 22:36:09 | 显示全部楼层
弘毅 发表于 2013-9-2 22:16
SD卡是3.3V电平。。PRO mini是5V如果中间没有可靠的电平转换。。有时可以用有时不能用是很正常的
  1. /*
  2.   SD card test
  3.    
  4. This example shows how use the utility libraries on which the'
  5. SD library is based in order to get info about your SD card.
  6. Very useful for testing a card when you're not sure whether its working or not.
  7.        
  8. The circuit:
  9.   * SD card attached to SPI bus as follows:
  10. ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
  11. ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
  12. ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
  13. ** CS - depends on your SD card shield or module.
  14.                 Pin 4 used here for consistency with other Arduino examples


  15. created  28 Mar 2011
  16. by Limor Fried
  17. modified 9 Apr 2012
  18. by Tom Igoe
  19. */
  20. // include the SD library:
  21. #include <SD.h>

  22. // set up variables using the SD utility library functions:
  23. Sd2Card card;
  24. SdVolume volume;
  25. SdFile root;

  26. // change this to match your SD shield or module;
  27. // Arduino Ethernet shield: pin 4
  28. // Adafruit SD shields and modules: pin 10
  29. // Sparkfun SD shield: pin 8
  30. const int chipSelect = 4;   

  31. void setup()
  32. {
  33. // Open serial communications and wait for port to open:
  34.   Serial.begin(9600);
  35.    while (!Serial) {
  36.     ; // wait for serial port to connect. Needed for Leonardo only
  37.   }


  38.   Serial.print("\nInitializing SD card...");
  39.   // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  40.   // Note that even if it's not used as the CS pin, the hardware SS pin
  41.   // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  42.   // or the SD library functions will not work.
  43.   pinMode(10, OUTPUT);     // change this to 53 on a mega


  44.   // we'll use the initialization code from the utility libraries
  45.   // since we're just testing if the card is working!
  46.   if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  47.     Serial.println("initialization failed. Things to check:");
  48.     Serial.println("* is a card is inserted?");
  49.     Serial.println("* Is your wiring correct?");
  50.     Serial.println("* did you change the chipSelect pin to match your shield or module?");
  51.     return;
  52.   } else {
  53.    Serial.println("Wiring is correct and a card is present.");
  54.   }

  55.   // print the type of card
  56.   Serial.print("\nCard type: ");
  57.   switch(card.type()) {
  58.     case SD_CARD_TYPE_SD1:
  59.       Serial.println("SD1");
  60.       break;
  61.     case SD_CARD_TYPE_SD2:
  62.       Serial.println("SD2");
  63.       break;
  64.     case SD_CARD_TYPE_SDHC:
  65.       Serial.println("SDHC");
  66.       break;
  67.     default:
  68.       Serial.println("Unknown");
  69.   }

  70.   // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  71.   if (!volume.init(card)) {
  72.     Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
  73.     return;
  74.   }


  75.   // print the type and size of the first FAT-type volume
  76.   uint32_t volumesize;
  77.   Serial.print("\nVolume type is FAT");
  78.   Serial.println(volume.fatType(), DEC);
  79.   Serial.println();
  80.   
  81.   volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  82.   volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  83.   volumesize *= 512;                            // SD card blocks are always 512 bytes
  84.   Serial.print("Volume size (bytes): ");
  85.   Serial.println(volumesize);
  86.   Serial.print("Volume size (Kbytes): ");
  87.   volumesize /= 1024;
  88.   Serial.println(volumesize);
  89.   Serial.print("Volume size (Mbytes): ");
  90.   volumesize /= 1024;
  91.   Serial.println(volumesize);

  92.   
  93.   Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  94.   root.openRoot(volume);
  95.   
  96.   // list all files in the card with date and size
  97.   root.ls(LS_R | LS_DATE | LS_SIZE);
  98. }


  99. void loop(void) {
  100.   
  101. }
复制代码
以上代码可以正常执行的,说明操作SD卡模块是可以的
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-9-2 22:38:31 | 显示全部楼层
本帖最后由 万马奔腾 于 2013-9-2 22:40 编辑
万马奔腾 发表于 2013-9-2 22:36
以上代码可以正常执行的,说明操作SD卡模块是可以的
  1. /*
  2. Simple SD Audio example, shows the usage of most functions
  3. via terminal at serial communication port.

  4. This example shows how to use the SimpleSDAudio library for audio playback.
  5. You need:
  6. - An Arduino with ATmega168/ATmega368 or better
  7. - An SD-Card connected to Arduinos SPI port (many shields will do)
  8.    -> copy some converted audio files on freshly formated SD card into root folder
  9. - A passive loudspeaker and resistor or better: active speakers (then stereo output will be possible)

  10. Audio signal output is at the following pin:
  11. - Arduino with ATmega168/328   (many non-mega Arduinos): Pin 9
  12. - Arduino with ATmega1280/2560 (many mega Arduinos)    : Pin 44

  13. Using passive speaker:       
  14.     Audio-Pin --- -[100 Ohm resistor]- ---- Speaker ---- GND
  15.    
  16. Using amplifier / active speaker / line-in etc.:
  17.     Audio-Pin --||--------------[10k resistor]----+----[1k resistor]---- GND
  18.               100nF capacitor                   to amp

  19. See SimpleSDAudio.h or our website for more information:
  20. http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio

  21. created  29 Jun 2012 by Lutz Lisseck
  22. */
  23. #include <SimpleSDAudio.h>

  24. // Callback target, prints output to serial
  25. void DirCallback(char *buf) {
  26.   Serial.println(buf);
  27. }

  28. char AudioFileName[16];

  29. // Create static buffer
  30. #define BIGBUFSIZE (2*512)      // bigger than 2*512 is often only possible on Arduino megas!
  31. uint8_t bigbuf[BIGBUFSIZE];

  32. // helper function to determine free ram at runtime
  33. int freeRam () {
  34.   extern int __heap_start, *__brkval;
  35.   int v;
  36.   return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
  37. }

  38. void setup()
  39. {
  40. // Open serial communications and wait for port to open:
  41.   Serial.begin(9600);
  42.    while (!Serial) {
  43.     ; // wait for serial port to connect. Needed for Leonardo only
  44.   }
  45.   
  46.   Serial.print(F("Free Ram: "));
  47.   Serial.println(freeRam());
  48.   
  49.   // Setting the buffer manually for more flexibility
  50.   SdPlay.setWorkBuffer(bigbuf, BIGBUFSIZE);
  51.   
  52.   Serial.print(F("\nInitializing SimpleSDAudio V" SSDA_VERSIONSTRING " ..."));  
  53.   
  54.   // If your SD card CS-Pin is not at Pin 4, enable and adapt the following line:
  55.   //SdPlay.setSDCSPin(10);
  56.   
  57.   // Select between SSDA_MODE_FULLRATE or SSDA_MODE_HALFRATE (62.5kHz or 31.25kHz)
  58.   // and the output modes SSDA_MODE_MONO_BRIDGE, SSDA_MODE_MONO or SSDA_MODE_STEREO
  59.   if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO)) {
  60.     Serial.println(F("initialization failed. Things to check:"));
  61.     Serial.println(F("* is a card is inserted?"));
  62.     Serial.println(F("* Is your wiring correct?"));
  63.     Serial.println(F("* maybe you need to change the chipSelect pin to match your shield or module?"));
  64.     Serial.print(F("Error code: "));
  65.     Serial.println(SdPlay.getLastError());
  66.     while(1);
  67.   } else {
  68.     Serial.println(F("Wiring is correct and a card is present."));
  69.   }
  70.   

  71. }


  72. void loop(void) {
  73.   uint8_t count=0, c, flag;
  74.   
  75.   Serial.println(F("Files on card:"));
  76.   SdPlay.dir(&DirCallback);

  77. ReEnter:
  78.   count = 0;
  79.   Serial.println(F("\r\nEnter filename (send newline after input):"));
  80.   do {
  81.     while(!Serial.available()) ;
  82.     c = Serial.read();
  83.     if(c > ' ') AudioFileName[count++] = c;
  84.   } while((c != 0x0d) && (c != 0x0a) && (count < 14));
  85.   AudioFileName[count++] = 0;
  86.   
  87.   Serial.print(F("Looking for file... "));
  88.   if(!SdPlay.setFile(AudioFileName)) {
  89.     Serial.println(F(" not found on card! Error code: "));
  90.     Serial.println(SdPlay.getLastError());
  91.     goto ReEnter;
  92.   } else {
  93.    Serial.println(F("found."));
  94.   }   

  95.   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."));
  96.   flag = 1;
  97.   
  98.   while(flag) {
  99.     SdPlay.worker();
  100.     if(Serial.available()) {
  101.       c = Serial.read();
  102.       switch(c) {
  103.          case 's':
  104.            SdPlay.stop();
  105.            Serial.println(F("Stopped."));
  106.            break;
  107.            
  108.          case 'p':
  109.            SdPlay.play();
  110.            Serial.println(F("Play."));
  111.            break;
  112.            
  113.          case 'h':
  114.            SdPlay.pause();
  115.            Serial.println(F("Pause."));
  116.            break;   
  117.    
  118.          case 'd':
  119.            SdPlay.deInit();
  120.            Serial.println(F("SdPlay deinitialized. You can now safely remove card. System halted."));
  121.            while(1) ;
  122.            break;  
  123.             
  124.          case 'f':
  125.            flag = 0;
  126.            break;
  127.      
  128.          case 'v':
  129.            Serial.print(F("Status: isStopped="));
  130.            Serial.print(SdPlay.isStopped());
  131.            Serial.print(F(", isPlaying="));
  132.            Serial.print(SdPlay.isPlaying());
  133.            Serial.print(F(", isPaused="));
  134.            Serial.print(SdPlay.isPaused());
  135.            Serial.print(F(", isUnderrunOccured="));
  136.            Serial.print(SdPlay.isUnderrunOccured());
  137.            Serial.print(F(", getLastError="));
  138.            Serial.println(SdPlay.getLastError());
  139.            Serial.print(F("Free RAM: "));
  140.            Serial.println(freeRam());
  141.            break;      
  142.       }
  143.     }
  144.   }
  145.   
  146.   
  147. }
复制代码
但是这段代码采用同样的接线,就出现错误了 串口输出("initialization failed. Things to check

如果是操作电平的问题,楼上代码串口输出也会出现错误啊~
回复 支持 反对

使用道具 举报

发表于 2013-9-8 21:57:17 | 显示全部楼层
万马奔腾 发表于 2013-9-2 22:38
但是这段代码采用同样的接线,就出现错误了 串口输出("initialization failed. Things to check

如果是 ...

{:soso_e103:} 这就好奇怪了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-6 10:21 , Processed in 0.079433 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表