Noise on Due DAC when reading from MicroSD through SPI

lencinhaus:
Hi all,
I know this has already been asked (Noise on Due Dac - Arduino Due - Arduino Forum) but since noone is answering on that topic I'm hoping to have better luck here.
I'm an experienced programmer but I'm just beginning with electronics, so please bear with me if I write silly stuff.
I'm trying to run the SimpleAudioPlayer example on a Due (see the code at Audio - Arduino Reference), reading a mono WAV file from a microSD card and playing it through the DAC, which is connected to an amplifier breakout, which in turn is connected to a speaker. See the attached images for details.
Everything works fine, except that there's a ground noise mixed with the audio that seems to be related to the microSD card reading.
The microSD card socket is directly wired to the SPI interface of the DUE, since it already works at 3.3v which is the required level for microSD. More specifically, I've attached the pins as follows (see SD card - Wikipedia for microSD pin numbering, and SPI - Arduino Reference for Arduino SPI header pin numbering):

  • microSD pin 2 (nCS) to Digital Pin 10
  • microSD pin 3 (DI) to SPI MOSI (pin 4 of the SPI header)
  • microSD pin 4 (VDD) to 3.3v Pin
  • microSD pin 5 (CLK) to SPI SCK (pin 3 of the SPI header)
  • microSD pin 6 (VSS) to GND Pin
  • microSD pin 7 (DO) to SPI MISO (pin 1 of the SPI header)
  • microSD pin 1 and 8 not wired to anithing

The WAV files reads fine, so I guess my wiring is correct (at least from at logic level).

I'm using Sparkfun's Mono Audio Amp Breakout with TPA2005D1 as an amplifier, see https://www.sparkfun.com/products/11044. The DAC0 and GND pins are connected to the amp's input + and - respectively. The amp's power + and - are connected to pins 5.5v and GND on the arduino (I've already tried using 3.3 but the noise is still there). The amp's output + and - are connected to a 1.5W speaker (http://it.rs-online.com/web/p/altoparlanti-miniatura/7564618/).
All grounds (amp input-, amp power- and microsd pin 6) are connected to the same rail on the breadboard, which is then connected to a single GND pin on the arduino.

Things I've tried so far:

  • switching DAC0 with DAC1: STILL noise
  • powering the amp with 3.3v instead of 5v: STILL noise
  • disconnecting ONLY DAC0 from the amp's input+: STILL noise at a lower volume
  • disconnecting the microSD card completely so that nothing is read but the amp is powered: NO noise
  • removing sparkfun's amp and attaching an external amplifier with speakers to DAC0: NO noise
  • disconnecting DAC0 and GND from the amp's input, and connecting an external audio source to the amp's input (while it's still powered from the arduino): NO noise

Please help me, I have to ship this project for next week and the noise isn''t really acceptable. If required I can provide an mp3 with an example of the noise I'm hearing, and/or a complete schematic of the circuit.
Thanks in advance to everyone!
lorenzo

Finally, the code I'm using (it's the same as the SimpleAudioPlayer example, just modified to loop the wav indefinitely and use pin 10 as CS for the SPI):

/*

Simple Audio Player

Demonstrates the use of the Audio library for the Arduino Due

Hardware required :

  • Arduino shield with a SD card on CS4
  • A sound file named "test.wav" in the root directory of the SD card
  • Speaker attched to ground and DAC0

Original by Massimo Banzi September 20, 2012
Modified by Scott Fitzgerald October 19, 2012

This example code is in the public domain

http://arduino.cc/en/Tutorial/SimpleAudioPlayer

*/

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

void setup()
{
  // debug output at 9600 baud
  Serial.begin(9600);

// setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(10)) {
    Serial.println(" failed!");
    return;
  }
  Serial.println(" done.");
  // hi-speed SPI transfers
  SPI.setClockDivider(4);

// 44100Khz mono
  // 100 mSec of prebuffering.
  Audio.begin(44100, 100);
}

void loop()
{
  int count=0;

// open wave file from sdcard
  File myFile = SD.open("DAFT.WAV");
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }

const int S=1024; // Number of samples to read in block
  short buffer[S];

Serial.print("Playing");
  // until the file is not finished
  while(true) {
    if(!myFile.available()) myFile.seek(0);
    // read from the file into buffer
    myFile.read(buffer, sizeof(buffer));

// Prepare samples
    int volume = 1024;
    Audio.prepare(buffer, S, volume);
    // Feed samples to audio
    Audio.write(buffer, S);

// Every 100 block print a '.'
    count++;
    if (count == 100) {
      Serial.print(".");
      count = 0;
    }
  }
  myFile.close();

Serial.println("End of file. Thank you for listening!");
  while (true) ;
}