
Originally Posted by
DD4WH
Would be nice if anybody has additional ideas?
Frank,
Have you gotten rid of the crackling?
I had an issue where the T4 SCK pin13 was extremely sensitive just trying to play the 'WavFilePlayer'. The SCK would pick up some kind of noise and cause the SDcard to not work and a bunch of bussing and static.
I already posted some attempts in an earlier post and have since modified them as below:
Code:
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_00 = 0x1F808; // SCL, hysterisus, pullup at 22K, open drain enable, low speed, drive strength at R0 (150 ohm)
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_01 = 0x1F808; // SDA
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_09 = 0x8; // MCLK, low speed, drive strength at R0 (150 ohm).
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_10 = 0x8; // BCLK
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_11 = 0x8; // LRCLK
IOMUXC_SW_PAD_CTL_PAD_GPIO_B1_01 = 0x8; // OUT1A
IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_02 = 0x8; // MOSI mdr20190828 helped get to SDTEST1.WAV & SDTEST2.WAV test
IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_03 = 0x8; // SCK mdr20190828 reqd in myT4_SdCardTest
IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_01 = 0x10000; //MISO mdr20190831 hysterisus+default for WavFilePlayer
Each one of those changes seemed to either be required or helpful, none seemed to hurt. Note that I added hysteresis to the inputs.
However, in messing around with the ILI9341 display discovered that even without the display just adding its's req'd stuff:
#include "ILI9341_t3.h"
const uint8_t TFT_DC = 5;
const uint8_t TFT_CS = 9;
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
and adding
tft.begin(); as the first line in setup() seemed to cure the whole issue. I can remove all the tweaks above.
I think something is not getting set correctly somewhere with a T4 library.
Here's my complete code:
Code:
#define MYVERSION_STUFF "myT4WavDisplay, 2019/9/2"
/* Simple WAV file player example from WaveFilePlayer
* mdr20190902 After installing 100 ohm resistor from T4 pin13 to audio board pin14 this will play but only after having played
* 'myT4_DemoSauce' first, and then load and run. Won't work from just plugging in. fixed, just have to add tft.begin(); to
* make it work. Don't need all the IOMUX stuff.
* */
#include <SPI.h>
#include <SD.h>
#include "ILI9341_t3.h"
#include "font_Arial.h"
#include <Wire.h>
#include <SerialFlash.h>
#include <Audio.h>
// Use these with the Teensy Audio Shield and Teesny 4.0 mdr20190823
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 11
#define SDCARD_SCK_PIN 13
// TFT pins
const uint8_t TFT_DC = 5;
const uint8_t TFT_CS = 9;
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
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() {
tft.begin(); //this seems to make the audio work
tft.setRotation( 1 );
tft.fillScreen(ILI9341_BLACK);
// Serial
if( true ) {
Serial.begin( 9600 );
tft.setTextColor(ILI9341_YELLOW);
tft.setFont(Arial_18);
tft.setCursor(10, 42);
tft.print(MYVERSION_STUFF);
tft.setTextColor(ILI9341_GREEN);
tft.setFont(Arial_18);
while (!Serial && millis() < 5000) { // wait for Arduino Serial Monitor
tft.fillRect(118, 182, 42, 18, ILI9341_BLACK);
tft.setCursor(118, 182);
tft.print((5000.0 - (float)millis()) / 1000.0, 1);
tft.print(" sec");
delay(100);
}
}
//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.4);
//mdr20190828
//from: https://forum.pjrc.com/threads/57167-Teensy-4-0-I2S-Support?p=213128&viewfull=1#post213128
// defaults were all 0x10B0 which is keeper, Medium speed (100 Mhz), drive strength = R0/6 = 150/6 = 25 ohms (the second strongest drive strength available) // My changes were:
//page 658 if nanual
//*
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_00 = 0x1F808; // SCL, pullup at 22K, open drain enable, low speed, drive strength at R0 (150 ohm)
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_01 = 0x1F808; // SDA
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_09 = 0x8; // MCLK, low speed, drive strength at R0 (150 ohm).
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_10 = 0x8; // BCLK
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_11 = 0x8; // LRCLK
IOMUXC_SW_PAD_CTL_PAD_GPIO_B1_01 = 0x8; // OUT1A
IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_02 = 0x8; // MOSI mdr20190828 helped get to SDTEST1.WAV & SDTEST2.WAV test
IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_03 = 0x8; // SCK mdr20190828 reqd in myT4_SdCardTest
IOMUXC_SW_PAD_CTL_PAD_GPIO_B0_01 = 0x10000; //MISO mdr20190831 hysterisus+default for WavFilePlayer
//*/
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
// 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);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setFont(Arial_24);
tft.setCursor(10, 80);
tft.print(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);
tft.setTextColor(ILI9341_GREEN);
tft.setFont(Arial_18);
// Simply wait for the file to finish playing.
unsigned long started=millis();
while (playWav1.isPlaying()) {
tft.fillRect(118, 182, 62, 18, ILI9341_BLACK);
tft.setCursor(118, 182);
tft.print((float)(millis()-started) / 1000.0, 1);
tft.print(" sec");
delay(100);
// 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("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
delay(500);
playFile("SDTEST2.WAV");
delay(500);
playFile("SDTEST3.WAV");
delay(500);
playFile("SDTEST4.WAV");
delay(1500);
}