Audio Playback (sd wav) + TFT Display = can it be done?

isaacjacobson

Well-known member
My first time working with a larger (3.5") TFT display. I noticed that the display interrupts the audio playback during the refresh. I've scraped through the forum [as best as I could] and didn't see anyone else running into this. Is the issue my setup? Or is it just known and accepted the SD wav can't occur during a TFT refresh?

My guess [and hope] is that I am doing something wrong.

Hardware Setup
Example Code
Code:
#include <Adafruit_HX8357.h>
#include <Audio.h>
#include "SD.h"

#define TFT_CS         10
#define TFT_RST        32
#define TFT_DC         33
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);

AudioPlaySdWav playSdWav1;
AudioOutputI2S audioOutput; 
AudioConnection patchCord1(playSdWav1, 0, audioOutput, 0);
AudioConnection patchCord2(playSdWav1, 1, audioOutput, 1);

void setup(void) {
  tft.begin();
  tft.fillScreen(HX8357_BLACK);
 
  SD.begin(BUILTIN_SDCARD);

  AudioMemory(10);
  playSdWav1.play("SDTEST1.WAV"); // audio start
}


void loop() {
  tft.fillScreen(HX8357_RED); // audio stops here
  delay(1000); // audio plays here
  tft.fillScreen(HX8357_GREEN); // audio stops here
  delay(1000); // audio plays here
  tft.fillScreen(HX8357_BLUE); // audio stops here
  delay(1000); // audio plays here
}


Is reliable SD Wav playback incompatible with a 3.5" TFT display over SPI? Or is there a simple solution? 🤞🤞🤞
 
I would suggest using a different CS pin than 10, since the audio adapter uses pin 10 for the SD card on the audio adapter. Yes, given you don't have a SD card in the audio adapter, it may not be an issue, but perhaps it could be. You also don't want pin 6 (which is used for the audio adapter's flash memory chip).

However, I can imagine that some devices disable interrupts for a long time, and it could mean the SD card is not getting the interrupts fast enough to keep the sound being smooth.

If you were using a SD card on the main SPI bus, it may be the display doesn't have the proper calls to share the SPI bus, but the builtin SD card uses a separate SPI bus for the card.

Another wild shot to try is increasing the number of audio buffers used (bump up the 10 in the AudioMemory call).
 
Last edited:
I appreciate the response, as it ultimately led me to a solution...

Another wild shot to try is increasing the number of audio buffers used (bump up the 10 in the AudioMemory call).
I did try several larger numbers there (20, 50, 100, etc), but no such luck.

I would suggest using a different CS pin than 10, since the audio adapter uses pin 10 for the SD card on the audio adapter. Yes, given you don't have a SD card in the audio adapter, it may not be an issue, but perhaps it could be. You also don't want pin 6 (which is used for the audio adapter's flash memory chip).
It seems like this was the culprit.

My setup is using a MicroMod carrier with fixed wiring that uses CS 10 for the TFT. All that to say I couldn't merely change the CS pin. However; I did locate the specific code within the audio library that was causing SPI interruptions... after commenting out those lines, it worked! Both the screen and sd wav audio are simultaneously working great.

From "spi_interupt.h"
Code:
static inline void AudioStartUsingSPI(void) {
    // SPI.usingInterrupt(IRQ_SOFTWARE);
    // AudioUsingSPICount++;
}

static inline void AudioStopUsingSPI(void) {
//     if (AudioUsingSPICount == 0 || --AudioUsingSPICount == 0)
//         SPI.notUsingInterrupt(IRQ_SOFTWARE);
// }

#else

static inline void AudioStartUsingSPI(void) {
    // SPI.usingInterrupt(IRQ_SOFTWARE);
}

That said – is there a more 'proper' way of preventing the SPI interrupts from the audio library? I'm worried that this might 'break' something else by merely commenting out these lines.

Also, if I'm using SDIO for an SD card (instead of SPI) and I'm not using memory over SPI, are there any issues with disabling the SPI interrupts of the audio library?
 
Back
Top