Hi, I've been messing around with using the CS42448 codec with a teensy 3.6, based on the design given in this article (thanks Paul!): https://hackaday.io/project/2984-teensy-audio-library/log/57537-tdm-support-for-many-channel-audio-io
I think this would be a pretty cool format for various audio projects, I managed to clone the PCB and add some stuff I wanted like preamps and power input.
I'm running into an issue however where one of the pins for the built-in SD card on the teensy is given a different function in regards to the codec, and the two seem to be mutually exclusive (as soon as I start using the SD card for wav audio the codec stops working). Pin 11, which is MOSI for the built-in SD card is connected to something called MCLK on the codec.
Wondering what the best solution is to solve this? I could build an SD card socket into my PCB, and switch the SPI function to the alternate pins, but this seems pretty wasteful. Wondering if it's possible to switch this MCLK function to another pin? Or if there's something else here I might be missing? Given that the two are pretty likely to be used together sticking a codec signal on the same pin used by the SD card seems like a strange choice.
Here is the code I am using to test, I get output on the built-in DACs, but no output from the codec :/. Please advise!
I think this would be a pretty cool format for various audio projects, I managed to clone the PCB and add some stuff I wanted like preamps and power input.
I'm running into an issue however where one of the pins for the built-in SD card on the teensy is given a different function in regards to the codec, and the two seem to be mutually exclusive (as soon as I start using the SD card for wav audio the codec stops working). Pin 11, which is MOSI for the built-in SD card is connected to something called MCLK on the codec.
Wondering what the best solution is to solve this? I could build an SD card socket into my PCB, and switch the SPI function to the alternate pins, but this seems pretty wasteful. Wondering if it's possible to switch this MCLK function to another pin? Or if there's something else here I might be missing? Given that the two are pretty likely to be used together sticking a codec signal on the same pin used by the SD card seems like a strange choice.
Here is the code I am using to test, I get output on the built-in DACs, but no output from the codec :/. Please advise!
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playWav[10];
AudioOutputTDM tdm1;
AudioOutputAnalogStereo dacs;
AudioSynthWaveformSine testSine;
AudioConnection patchCord1(testSine, 0, tdm1, 0);
AudioConnection patchCord2(playWav[1], 0, tdm1, 2);
AudioConnection patchCord3(playWav[2], 0, tdm1, 4);
AudioConnection patchCord4(playWav[3], 0, tdm1, 6);
AudioConnection patchCord5(playWav[4], 0, tdm1, 8);
AudioConnection patchCord6(playWav[5], 0, tdm1, 10);
AudioConnection patchCord7(playWav[6], 0, tdm1, 12);
AudioConnection patchCord8(playWav[7], 0, tdm1, 14);
AudioConnection patchCord10(playWav[8], 0, dacs, 0);
AudioConnection patchCord11(playWav[9], 0, dacs, 1);
AudioControlCS42448 cs42448_1;
// 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
const char *files[] = {"FIRE1.wav", "FIRE2.wav", "FIRE3.wav", "FIRE4.wav", "RAIN1.wav", "RAIN2.wav", "RAIN3.wav", "RAIN4.wav",
"WIND1.wav", "WIND2.wav", "WIND3.wav", "WIND4.wav", "ANIMAL1.wav", "ANIMAL2.wav", "ANIMAL3.wav", "ANIMAL4.wav"};
void setup() {
delay(100);
Serial.begin(115200);
delay(100);
pinMode(0, OUTPUT);
digitalWrite(0, HIGH);
AudioMemory(256);
dacs.analogReference(INTERNAL);
testSine.amplitude(1);
testSine.frequency(100);
SPI.begin();
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
while (!(SD.begin(SDCARD_CS_PIN))) {
// stop here, but print a message repetitively, try again
Serial.println("Unable to access the SD card");
// delay(500);
}
cs42448_1.enable();
cs42448_1.volume(1);
Serial.println("Setup Done!");
}
int timer = 0;
void loop() {
//loop wav file playback
for(int i = 0; i < 10; ++i){
if(!(playWav[i].isPlaying())){
playFileFromPlayer(files[i], i);
}
}
//blink LED
if(millis() - timer > 250){
digitalWrite(0, !digitalRead(0));
timer = millis();
}
}
void playFileFromPlayer(const char *filename, int player)
{
Serial.print("Playing file: ");
Serial.print(filename);
// Start playing the file. This sketch continues to
// run while the file plays.
playWav[player].play(filename);
// A brief delay for the library read WAV info
delay(5);
Serial.println(" Check!");
}