Wrote the following Code to test. It uses the standard arduino wire library, just to be sure, that this part works.
After sending the defined values to the amp, it reads the value of the first register. It outputs the device address, register address, register value, a test char and a test string over Serial.
/*
#include <Wire.h> // I2C Library
// --- Audio Amplifier I2C definitions ---
#define AMP_ADDRESS 0x60 // TPA6130A2 device address
// Register 1: HP_EN_L, HP_EN_R, Mode[1], Mode[0], Reserved, Reserved, Reserved, Thermal, SWS
#define AMP_REG1 0x1 // TPA6130A2 register 1 address
#define AMP_REG1_SETUP 0xc0 // default configuration: 11000000 - both channels enabled
// Register 2: Mute_L, Mute_R, Volume[5-0]
#define AMP_REG2 0x2 // TPA6130A2 register 2 address
#define AMP_REG2_SETUP 0x34 // default configuration: 00110100 - both channels on –0.3 dB Gain
void setup() {
delay(200);
Serial.begin(9600);
Wire.begin();
initializeAmp();
}
void initializeAmp() {
amp_writeTo(AMP_REG1, AMP_REG1_SETUP);
amp_writeTo(AMP_REG2, AMP_REG2_SETUP);
Wire.beginTransmission(AMP_ADDRESS); // start transmission to device
Serial.println(AMP_ADDRESS,BIN);
Wire.write( AMP_REG1 ); // send register address
Serial.println(AMP_REG1,BIN);
Wire.requestFrom(AMP_ADDRESS, 8); // request 8 bytes from device
while(Wire.available()) // slave may send less than requested
{
byte c = Wire.read(); // receive a byte
Serial.print(c,BIN); // print the byte as binary
Serial.print("."); // print test character
}
Wire.endTransmission();
Serial.println();
Serial.println("Amplifier Initialized!");
}
void amp_writeTo(byte address, byte val) {
Wire.beginTransmission(AMP_ADDRESS); // start transmission to device
Wire.write( address ); // send register address
Wire.write( val ); // send value to write
Wire.endTransmission(); // end transmission
}
void loop() {
}
The output looks like that:
1100000
1
Amplifier Initialized!
Now it seems like the amp is not responding to the request, because it doesn't send anything back. Is there a method to request the address of all devices on the I2C-bus to see, if I just got that wrong?