Skip to content

Instantly share code, notes, and snippets.

@njtbot
Last active December 24, 2015 07:19
Show Gist options
  • Save njtbot/6763166 to your computer and use it in GitHub Desktop.
Save njtbot/6763166 to your computer and use it in GitHub Desktop.
Example interface register write routine for Analog Devices ADAU1701 DSP in C.
/* Volume levels */
const int dspVolume[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x05,
0x00, 0x00, 0x00, 0x06,
0x00, 0x00, 0x00, 0x07,
0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x09,
0x00, 0x00, 0x00, 0x0A,
0x00, 0x00, 0x00, 0x0B,
0x00, 0x00, 0x00, 0x0C,
0x00, 0x00, 0x00, 0x0D,
0x00, 0x00, 0x00, 0x0E,
0x00, 0x00, 0x00, 0x0F,
0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x11,
0x00, 0x00, 0x00, 0x12,
0x00, 0x00, 0x00, 0x13,
0x00, 0x00, 0x00, 0x14,
0x00, 0x00, 0x00, 0x15,
0x00, 0x00, 0x00, 0x16,
0x00, 0x00, 0x00, 0x17,
0x00, 0x00, 0x00, 0x18,
0x00, 0x00, 0x00, 0x19,
0x00, 0x00, 0x00, 0x1A,
0x00, 0x00, 0x00, 0x1B,
0x00, 0x00, 0x00, 0x1C,
0x00, 0x00, 0x00, 0x1D,
0x00, 0x00, 0x00, 0x1E,
0x00, 0x00, 0x00, 0x1F,
0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x21,
};
/* Function to write volume level to Interface Register 0 */
void UpdateVolume(int newVolumeIndex) {
int kk = 0;
AllowInterfaceWrite();
I2CMasterStart();
I2CMasterWriteByte(DSP_WRITE_ADDRESS); /* DSP address */
I2CMasterWriteByte(0x08); /* Subaddress */
I2CMasterWriteByte(0x00);
while (kk < 4) {
I2CMasterWriteByte(dspVolume[(newVolumeIndex * 4) + kk]); /* New volume data - 4 bytes */
kk++;
}
I2CMasterStop();
DisallowInterfaceWrite();
}
/* Unlock interface register */
void AllowInterfaceWrite() {
I2CMasterStart();
I2CMasterWriteByte(DSP_WRITE_ADDRESS);
I2CMasterWriteByte(0x08); /* DSP Core Register */
I2CMasterWriteByte(0x1C);
I2CMasterWriteByte(0x00); /* Set IFCW bit to allow writing to interface registers */
I2CMasterWriteByte(0x5C);
I2CMasterStop();
}
/* Lock interface register */
void DisallowInterfaceWrite() {
I2CMasterStart();
I2CMasterWriteByte(DSP_WRITE_ADDRESS);
I2CMasterWriteByte(0x08); /* DSP Core Register */
I2CMasterWriteByte(0x1C);
I2CMasterWriteByte(0x00); /* Clear IFCW bit to disallow writing to interface registers */
I2CMasterWriteByte(0x1C);
I2CMasterStop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment