// TAS5707 - 20W(8 Om / 18 V) STEREO DIGITAL AUDIO POWER AMPLIFIER
// 48-kHz 24 bit
// PVDD 8 V to 24 V
// AVDD/DVDD 3.3 V
// http://rcl-radio.ru
// liman324@yandex.ru
#define I2C_TAS5707 0x1B // Address chip
#define RESET 2 // RESET PIN
#define PDN 3 // PDN PIN
#include <Wire.h>
int vol;
void setup() {
delay(100);Wire.begin();Serial.begin(9600);
pinMode(RESET,OUTPUT);
pinMode(PDN,OUTPUT);
digitalWrite(PDN,HIGH);delay(100); Serial.println("POWER ON");
digitalWrite(RESET,HIGH);delay(100);Serial.println("RESET ON");
tas_init();
Serial.print("ID(0x70) 0x");Serial.println(wireRead(I2C_TAS5707,0x01),HEX);
}
void loop() {
// ERROR STATUS
Serial.print("ER 0b");
Serial.println(wireRead(I2C_TAS5707,0x02),BIN);
delay(1000);
}
void tas_init(){
wireWrite(I2C_TAS5707, 0x00, 0b01101100);
//[7:5][011][Fs]41.1/48kHz
//[4:2][011][MCLK_F]MCLK frequency = 256 × Fs
//[1:0][00]Reserved
wireWrite(I2C_TAS5707, 0x03, 0b10100000);
//[7][1][PWM high-pass](dc blocking) enabled
//[6][0]Reserved
//[5][1][unmute]Hard unmute on recovery from clock error
//[4:2][0]Reserved
//[1:0][00][de-emphasis]No de-emphasis
wireWrite(I2C_TAS5707, 0x04, 0b00000101);
//[7:4][0000]
//[3:0][0101][Format data]i2s_24bit
wireWrite(I2C_TAS5707, 0x05, 0b01000000);
//[7][0]Reserved
//[6][0][shutdown]normal operation
//[5:0][000000]Reserved
wireWrite(I2C_TAS5707, 0x06, 0b00000000);
//[7:2][000000]Reserved
//[1][0][Soft mute ch1]soft unmute
//[0][0][Soft mute ch2]soft unmute
wireWrite(I2C_TAS5707, 0x07, 0b00110000);
//[7:0][00110000][0dB][Master Volume]-79...24dB = 0b11001110...0b00000000
wireWrite(I2C_TAS5707, 0x08, vol);
//[7:0][CH1 Volume]-79...24dB = 0b11001110...0b00000000
wireWrite(I2C_TAS5707, 0x09, vol);
//[7:0][CH2 Volume]-79...24dB = 0b11001110...0b00000000
wireWrite(I2C_TAS5707, 0x0A, 0b00000000);
//[7][0]ignore write to reg 0x0A
//[1:0][00] 0 dB
wireWrite(I2C_TAS5707, 0x0E, 0b10010001);
//[7:3][10010]Reserved
//[2:0][001]volume slew 1024 steps
wireWrite(I2C_TAS5707, 0x10, 0b00000010);
//[7:3][00000]Reserved
//[2:0][010][MODULATION LIMIT]97.7%
wireWrite(I2C_TAS5707, 0x11, 0xAC);//DEF
wireWrite(I2C_TAS5707, 0x12, 0x54);//DEF
wireWrite(I2C_TAS5707, 0x13, 0xAC);//DEF
wireWrite(I2C_TAS5707, 0x14, 0x54);//DEF
wireWrite(I2C_TAS5707, 0x1A, 0b00000010);
//[7:5][000]Reserved
//[4:0][01111][START/STOP PERIOD]125.7ms 50% % duty cycle start/stop period
wireWrite(I2C_TAS5707, 0x1B, 0b11000000);//OSCILLATOR TRIM REGISTER
//[7][0]Reserved
//[6][1]Oscillator trim done (read only)
//[5:2][0000]Reserved
//[1][0]Select factory trim
//[0][0]Reserved
wireWrite(I2C_TAS5707, 0x1C, 0b00000010);
//[3:0][0010]Set back-end reset period to 299 ms
wireWrite32(I2C_TAS5707, 0x20, 0,0b00000001, 0b01110111, 0b01110010);
//[31:24][0x00]Reserved
//[23:16][00000001]DEF
//[15:8][01110111]DEF
//[7:0][01110010]DEF
wireWrite32(I2C_TAS5707, 0x25, 1,0b00000010, 0b00010011, 0b01000101);
//[31:24][0x00]Reserved
//[23:16][00000010]DEF
//[15:8][00010011]DEF
//[7:0][01000101]DEF
wireWrite32(I2C_TAS5707, 0x46, 0,0,0, 0b00000000);
//[31:24][0x00]Reserved
//[23:16][00000000]Reserved
//[15:8][00000000]Reserved
//[7:0][00000000]DEF
wireWrite32(I2C_TAS5707, 0x50, 0b00001111,0b11110000,0b10000000, 0b00000000);
//[31:24][00001111]DEF
//[23:16][11110000]DEF
//[15:8][10000000]DEF
//[7:0][00000000]DEF
}
byte wireRead(byte addr, byte reg){
Wire.beginTransmission(addr);
Wire.write (reg);
Wire.endTransmission();
Wire.requestFrom(addr,1);
while(Wire.available()<1);
byte value = Wire.read();
return value;
}
void wireWrite(byte addr, byte reg, byte data){
Wire.beginTransmission(addr);
Wire.write (reg);
Wire.write (data);
Wire.endTransmission();
}
void wireWrite32(byte addr, byte reg, byte data3, byte data2, byte data1, byte data0){
Wire.beginTransmission(addr);
Wire.write (reg);
Wire.write (data3);
Wire.write (data2);
Wire.write (data1);
Wire.write (data0);
Wire.endTransmission();
}