3.6 SD card issue, freezing before loop starts

Status
Not open for further replies.

propa

Well-known member
Hi,

I have tested a 2gb fat16, and 32gb san disk ultra using the play wav from sd and play raw from sd, neither work and hang up before getting to the main program loop. If no disk is inserted I get standard not found error.

When a card is in the serial monitor crashes and has crashed my computer twice now, completely froze it, I'm only using the examples playwav from sd, and changing to builtin sdcard, nothing should be going this drastically wrong.

Has anyone had this issue before?

I'm using an audio shield as well, wouldn't have thought it was going to cause any conflict.

SD > Cardinfo and files example work fine.

However trying to get wav played back has been a total mission.

Anyone else had this same mission?

Code:
// Simple WAV file player example
//
// Three types of output may be used, by configuring the code below.
//
//   1: Digital I2S - Normally used with the audio shield:
//         http://www.pjrc.com/store/teensy3_audio.html
//
//   2: Digital S/PDIF - Connect pin 22 to a S/PDIF transmitter
//         https://www.oshpark.com/shared_projects/KcDBKHta
//
//   3: Analog DAC - Connect the DAC pin to an amplified speaker
//         http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog
//
// To configure the output type, first uncomment one of the three
// output objects.  If not using the audio shield, comment out
// the sgtl5000_1 lines in setup(), so it does not wait forever
// trying to configure the SGTL5000 codec chip.
//
// The SD card may connect to different pins, depending on the
// hardware you are using.  Uncomment or configure the SD card
// pins to match your hardware.
//
// Data files to put on your SD card can be downloaded here:
//   http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
//
// This example code is in the public domain.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySdWav           playWav1;
// Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
AudioOutputI2S           audioOutput;
//AudioOutputSPDIF       audioOutput;
//AudioOutputAnalog      audioOutput;
AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;

void setup() {
  Serial.begin(9600);

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(8);

  // Comment these out if not using the audio adaptor board.
  // This may wait forever if the SDA & SCL pins lack
  // pullup resistors
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);


  if (!(SD.begin(BUILTIN_SDCARD))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void playFile(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.println(filename);

  // Start playing the file.  This sketch continues to
  // run while the file plays.
  playWav1.play(filename);

  // A brief delay for the library read WAV info
  delay(5);

  // Simply wait for the file to finish playing.
  while (playWav1.isPlaying()) {
    // uncomment these lines if you audio shield
    // has the optional volume pot soldered
    //float vol = analogRead(15);
    //vol = vol / 1024;
    // sgtl5000_1.volume(vol);
  }
}


void loop() {
  playFile("001.WAV");  // filenames are always uppercase 8.3 format
  delay(500);
}
 
Hello again,

I did another test and found when trying the Dump File example I get an error "Initializing SD card...card initialized.
error opening datalog.txt
"

So looking at the contents of a card is fine, reading the contents is causing trouble, using Teensy 3.6, Audio Shield plugged in by not used/switched on in the code.

Does this sound familiar to anyone? It's a 16gb San Disk ultra, that I've used in the wav trigger, so can confirm it works.

The only other thing to rule out is using a mac to format the card. Have a I just got a dodgy card?

This is the read out from cardinfo after formatting the card and adding sdtest.wav, is there any indication here that it's dodgy:

Code:
Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (Kbytes): 15538856
Volume size (Mbytes): 15174

Files found on the card (name, date and size in bytes): 
SPOTLI~1/     2019-05-14 15:17:30
  STORE-V2/     2019-05-14 15:17:30
    19A8A3~1/     2019-05-14 15:17:30
      PSID.DB       2019-05-14 15:28:10 8192
      TM~1.SNO      2019-05-14 15:17:30 0
      TM~1.LIO      2019-05-14 15:17:30 0
      LIO~1.CRE     2019-05-14 15:17:30 0
      TMP.CAB       2019-05-14 15:17:30 0
      CA~1.CRE      2019-05-14 15:17:30 0
      INDEXS~1      2019-05-14 15:28:10 28
      ~1.IND        2019-05-14 15:28:10 4096
      ~~2.IND       2019-05-14 15:17:40 16
      ~~~3.IND      2019-05-14 15:17:40 8
      ~~~~4.IND     2019-05-14 15:28:10 3277
      ~~~~~5.IND    2019-05-14 15:17:38 4096
      ~~~~~~34.IND  2019-05-14 15:17:40 336
      ~~~~~~37.IND  2019-05-14 15:17:30 4096
      ~~~~~~40.IND  2019-05-14 15:17:40 336
      ~~~~~~43.IND  2019-05-14 15:17:40 2056
      ~~~~~~46.IND  2019-05-14 15:17:40 8
      ~~~~~~49.IND  2019-05-14 15:17:40 832
      ~~~~~~51.IND  2019-05-14 15:17:38 13
      ~1.DIR        2019-05-14 15:17:38 65536
      LIVE~1.IND    2019-05-14 15:28:10 4096
      LIVE~~2.IND   2019-05-14 15:28:10 32768
      LIVE~~~3.IND  2019-05-14 15:28:10 16384
      LIVE~~~4.IND  2019-05-14 15:28:10 3277
      LIVE~~~5.IND  2019-05-14 15:17:30 4096
      LIVE~~72.IND  2019-05-14 15:17:30 8192
      LIVE~~75.IND  2019-05-14 15:17:30 4096
      LIVE~~78.IND  2019-05-14 15:17:30 8192
      LIVE~~81.IND  2019-05-14 15:17:38 8224
      LIVE~~84.IND  2019-05-14 15:17:38 1024
      LIVE~~88.IND  2019-05-14 15:17:42 65536
      LIVE~~91.IND  2019-05-14 15:28:10 1670
      LIVE~1.DIR    2019-05-14 15:17:38 65536
      STORE.DB      2019-05-14 15:17:42 118784
      STOR~1.DB     2019-05-14 15:28:10 118784
      REVERS~1      2019-05-14 15:17:42 65536
      TMPSPO~1.STA  2019-05-14 15:28:10 4096
      STORE_~1      2019-05-14 15:17:30 4
      JOURNA~1.COR/ 2019-05-14 15:17:30
      JOURNA~1.LIV/ 2019-05-14 15:17:30
      JOURNA~2.LIV/ 2019-05-14 15:17:30
      JOURNA~3.LIV/ 2019-05-14 15:17:30
        JOURNAL.1     2019-05-14 15:28:10 38
      JOURNA~4.LIV/ 2019-05-14 15:17:30
      JOURNA~1.ASS/ 2019-05-14 15:17:30
      JOURNA~2.ASS/ 2019-05-14 15:17:30
      JOURNA~1.HEA/ 2019-05-14 15:17:30
      JOURNA~1.MIG/ 2019-05-14 15:17:30
      JOURNA~2.MIG/ 2019-05-14 15:17:30
      JOURNA~1      2019-05-14 15:17:30 0
      JOURNA~1.SCA/ 2019-05-14 15:17:30
        RETIRE.2      2019-05-14 15:17:38 0
      SHUTDO~1      2019-05-14 15:28:10 4
      REVERS~1.SHA  2019-05-14 15:17:30 3136
      ~1.SHA        2019-05-14 15:17:40 4096
      STOR~1.UPD    2019-05-14 15:28:10 12
      PERMST~1      2019-05-14 15:28:10 553
      JOURNA~1.REP/ 2019-05-14 15:26:46
      CA~1.MOD      2019-05-14 15:26:46 0
      JOURNA~1.1    2019-05-14 15:28:10 140
      0DIREC~1.SHA  2019-05-14 15:17:38 1088
      ~~~~~175.SHA  2019-05-14 15:17:40 2
      LIVE~1.SHA    2019-05-14 15:17:40 4096
      LIVE~~2.SHA   2019-05-14 15:17:32 0
      LIVE~~~3.SHA  2019-05-14 15:17:32 0
      LIVE~~~4.SHA  2019-05-14 15:17:40 65536
      LIVE~~~5.SHA  2019-05-14 15:17:40 8
      LIVE~195.SHA  2019-05-14 15:17:40 2056
      LIVE0D~1.SHA  2019-05-14 15:17:40 1088
      LIVE~203.SHA  2019-05-14 15:17:34 1
      REVERS~1.UPD  2019-05-14 15:28:10 1
      TMPSPO~1.LOC  2019-05-14 15:28:10 5080
  STORE-V1/     2019-05-14 15:17:30
    VOLUME~1.PLI  2019-05-14 15:17:30 348
  VOLUME~1.PLI  2019-05-14 15:17:30 4113
RECORD2.RAW   2000-01-01 01:00:00 160256
SDTEST2.WAV   2019-05-14 15:27:54 1911162
_SDTES~1.WAV  2019-05-14 15:28:06 4096

Anything else I should check?
 
I have the same problem here. I am really surprised that not many people report this.

I am using Teensy 3.5 and want to play a WAV file from the built-in SD slot based on the WavFilePlayer example, but SD.begin(BUILTIN_SDCARD) freezes. After lots of debugging, I found out that as long as there is any playSdWav1.play(fileName) function call ANYWHERE in the code (every long after SD.begin) , SD.begin() will freeze when there is a card inside. And in this case, the serial monitor is also VERY laggy.

I have 10 brand new Teensy 3.5's and 4 different SD cards here but they are all the same.

Interestingly, this WORKS just fine if I use an external SD module.

I am designing a PCB powered by the 3.5 to play WAV from SD so I would be very grateful if someone could shed some light on this.
 
P.S. I am sorry I could not use code tag because I am accessing the site from Vietnam, and for whatever reason I am not sure, this forum bans access from Vietnam, so I am accessing through a web proxy. Hope they will lift the ban
 
@propa - please provide IDE and TeensyDuino version - OS info always welcome
Also if you could format one of the cards fresh and add known files - perhaps with the industry standard SD_Card_Formatter - Version I have is by TUXERA version 5.0.1 and says it is up to date.


P.S. I am sorry I could not use code tag because I am accessing the site from Vietnam, and for whatever reason I am not sure, this forum bans access from Vietnam, so I am accessing through a web proxy. Hope they will lift the ban

Code would be helpful - just paste the text into the reply message. Or put it on github or somewhere you can link to it perhaps.

Maybe add a file is difficult with upload - but code tag just wraps html descriptor around plain text and not sure how/why that would be blocked.

Code:
[C0DE]
// code goes here
// except replaced O's with Zero's to demonstrate
[/C0DE]
 
This is my code:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=343.00000381469727,3690.2000064849854
AudioOutputAnalogStereo  dacs1;          //xy=525.0000076293945,3693.2000064849854
AudioConnection          patchCord1(playSdWav1, 0, dacs1, 0);
AudioConnection          patchCord2(playSdWav1, 1, dacs1, 1);
// GUItool: end automatically generated code

// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN    BUILTIN_SDCARD
#define SDCARD_MOSI_PIN  11  // not actually used
#define SDCARD_SCK_PIN   13  // not actually used

void setup() {
  Serial.begin(115200);
  AudioMemory(8);
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void playFile(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.println(filename);

  playSdWav1.play(filename);
  delay(5);

  // Simply wait for the file to finish playing.
  while (playSdWav1.isPlaying()) {
  }
}

void loop() {
  playFile("SDTEST.WAV");  // filenames are always uppercase 8.3 format
  delay(3000);
}

As said, this code doesn't works with the built-in SD card slot as it freezes on SD.begin, but WORKS fine with an external SD module connected on pin 8 as I have tested. In that case, I just define #define SDCARD_CS_PIN 8.

On my system, as I am trying to debug this, I have just freshly installed the newest Arduino (1.8.9) and Teensyduino.

I am on Windows 10, and the cards in test are a Kingston Class 4 4GB, and a cheap 2GB (class not printed) with "cK" brand. Both work just fine.
 
Status
Not open for further replies.
Back
Top