Code:
const uint8_t resetPin = 16; // Teensy 3.2 codec shield reset pin v1.0 hardware
const uint8_t codecAddress = 0x18; // TLV320AIC3110
void setup() {
pinMode(resetPin, OUTPUT); // comment out if not Teensy diy audio codec
digitalWrite(resetPin, LOW); // comment out if not Teensy diy audio codec
delay(1);
digitalWrite(resetPin, HIGH); // comment out if not Teensy diy audio codec
init_codec(); // start up the codec
...
void init_codec()
{
Wire.begin();
writeCodec(0x0, 0x0); // select page 0
writeCodec(0x01, 0x01); // soft reset
writeCodec(0x04, 0x03); // pll clock in
writeCodec(0x05, 0x91); // pll power up
writeCodec(0x06, 0x08); // j = 8
writeCodecDual(0x07, 0x0, 0x0); // D = 0000
writeCodec(0x1B, 0x0); // i2s, wordlength 16
writeCodec(0x0B, 0x84); // NDAC is powered and set to 4
writeCodec(0x0C, 0x84); // MDAC is powered and set to 4
writeCodecDual(0x0D, 0x0, 0x80); // DOSR = 128, DOSR(9:8) = 0, DOSR(7:0) = 128
writeCodec(0x74, 0x0); // DAC -> volume control thru pin disable
writeCodec(0x44, 0x0); // DAC -> DRC disable
writeCodec(0x41, 0xD4); // DAC -> -22dB gain left
writeCodec(0x42, 0xD4); // DAC -> -22dB gain right
writeCodec(0x0, 0x01); // Select page 1
writeCodec(0x21, 0x4E); // De-pop, power on = 800 ms, step time = 4ms
writeCodec(0x1F, 0xC2); // HPL and HPR powered up
writeCodec(0x23, 0x44); // LDAC routed to HPL, RDAC routed to HPR
writeCodec(0x28, 0x06); // HPL unmute annd gain = 0dB
writeCodec(0x29, 0x06); // HPR unmute annd gain = 0dB
writeCodec(0x2A, 0x1C); // unmute class D left
writeCodec(0x2B, 0x1C); // unmute class D right
writeCodec(0x20, 0xC6); // power up class D drivers
writeCodec(0x24, 0x92); // enables HPL output analog volume, set = -9 dB
writeCodec(0x25, 0x92); // enables HPR output analog volume, set = -9 dB
writeCodec(0x26, 0x92); // enables HPL output analog volume, set = -9 dB
writeCodec(0x27, 0x92); // enables HPR output analog volume, set = -9 dB
writeCodec(0x0, 0x0); // select page 0
// select DAC DSP Processing Block PRB_P11
writeCodec(0x3C, 0x0B); //
writeCodec(0x00, 0x08); //
writeCodec(0x01, 0x04); //
writeCodec(0x00, 0x00); //
writeCodec(0x3F, 0xD6); // power up DAC left and right channels (soft step disable)
writeCodec(0x40, 0x0); // unmute DAC left and right channels
Wire.end();
}
void writeCodec(uint8_t registerVal, uint8_t dataVal)
{
Wire.beginTransmission(codecAddress);
Wire.write(registerVal); // set the address to write to
Wire.write(dataVal); // set the data to write
Wire.endTransmission(); // end
}
void writeCodecDual(uint8_t registerVal, uint8_t data0Val, uint8_t data1Val)
{
Wire.beginTransmission(codecAddress);
Wire.write(registerVal); // set the address to write to
Wire.write(data0Val); // set the data to write
Wire.write(data1Val); // set the data to write
Wire.endTransmission(); // end
}
I will try and play some music from the SD card next.