View Full Version : Teensy Audio Adapter strange I2C

04-21-2016, 08:16 AM
I've been trying to use a Teensy Audio Adapter with a Raspberry Pi 3. It's still 3.3 V, and all of the communication protocols are present.
I can send a master clock from a GPIO pin as I explain here:

And then I see 0a on running
i2cdetect -y 1
If I turn off that GPIO clock, that 0a disappears, so this much appears to be working.
If I run
i2cdump -y 1 0x0a w
I get a list of supposed registers:
0,8 1,9 2,a 3,b 4,c 5,d 6,e 7,f
00: 11a0 0000 0000 0000 0000 0000 0000 0000
08: 0000 0000 0000 0000 0000 0000 0000 0000
10: 0000 0000 0000 0000 0000 0000 0000 0000
.... and so on, all 0000 except the first one. If I then write OR read any of the registers, i2cdump returns the exact same list, but with different, changing values for address 00.
I suspect something is happening with the I2C address communication; I wonder if, instead of reading different registers, RPi's I2C (whether wiringpi, i2cset/get, pigpio, or smbus) is receiving a longer list of bytes and understanding 0x0000 as the register address for all of them???
I don't know how the Teensy Audio Adapter should work with I2C, but I can't imagine that this is not a mistake. Modify functions would be useless if you can't read values from the registers. Could anyone tell me, if you read individual addresses from the SGTL5000's register using I2C, whether you use Teensy or RPi to communicate with it, do you get this? Even after running my setup script (an adapted version of the Teensy SGTL5000 control driver startup), i2cdump shows me 1700 at address 0x0000 and the rest all 0000.
I've double and triple checked my wiring. I checked my soldering on the TAA pins. The board actually shows up at address 0x0a.

Here are the values I'm sending for the SGTL5000's configuration/initialization. As I said, most are from the Teensy Audio Library, but I'm using a different speed of master clock, so I activated PLL, etc.

CHIP_REF_CTRL = 0x0028
CHIP_ANA_CTRL = 0x0024
CHIP_PLL_CTRL = 0x0032
CHIP_CLK_CTRL = 0x0004
CHIP_I2S_CTRL = 0x0006
CHIP_DAC_VOL = 0x0010

pi.i2c_write_word_data(h,CHIP_ANA_POWER, 0x4060) # VDDD is externally driven with 1.8V
pi.i2c_write_word_data(h,CHIP_LINREG_CTRL, 0x006C) # VDDA & VDDIO both over 3.1V
pi.i2c_write_word_data(h,CHIP_REF_CTRL, 0x01F2) # VAG=1.575, normal ramp, +12.5% bias current
pi.i2c_write_word_data(h,CHIP_LINE_OUT_CTRL, 0x0F22) # LO_VAGCNTRL=1.65V, OUT_CURRENT=0.54mA
pi.i2c_write_word_data(h,CHIP_SHORT_CTRL, 0x4446) # allow up to 125mA
pi.i2c_write_word_data(h,CHIP_ANA_CTRL, 0x0137) # enable zero cross detectors
pi.i2c_write_word_data(h,CHIP_ANA_POWER, 0x40FF) # power up: lineout, hp, adc, dac
pi.i2c_write_word_data(h,CHIP_DIG_POWER, 0x0073) # power up all digital stuff

# delay(400)

pi.i2c_write_word_data(h,CHIP_LINE_OUT_VOL, 0x1D1D) # default approx 1.3 volts peak-to-peak
anap = 0x40FF | 0b0000010100000000
pi.i2c_write_word_data(h,CHIP_CLK_CTRL,0x0007) # 44.1 kHz, 256*Fs
pi.i2c_write_word_data(h,CHIP_I2S_CTRL,0x01b0) # SCLK=32*Fs, 16bit, I2S format
pi.i2c_write_word_data(h,CHIP_SSS_CTRL, 0x0010) # ADC->I2S, I2S->DAC
pi.i2c_write_word_data(h,CHIP_ADCDAC_CTRL, 0x0000) # disable dac mute
pi.i2c_write_word_data(h,CHIP_DAC_VOL, 0x3C3C) # digital gain, 0dB
pi.i2c_write_word_data(h,CHIP_ANA_HP_CTRL, 0x1818) # set volume (lowest level)
pi.i2c_write_word_data(h,CHIP_ANA_CTRL, 0x0036) # enable zero cross detectors

Anyone see any problem with the values I'm sending or the order? Or is the problem just that my RPi and my TAA are communicating haphazardly?


04-21-2016, 10:42 AM
I may have figured something out.
The SGTL5000 uses two-byte register addresses, while most of the I2C implementations I've been able to use assume 1-byte register addresses. It could explain how data gets corrupted while trying to read, as the first message sent to read a register is in fact a write message, and then the address desired can be potentially misunderstood.
I haven't yet had time to fix the problem to see if that's the only one, but this definitely explains why I2C isn't working as I wanted.

04-21-2016, 04:33 PM
In case anyone else comes looking for info, I have managed to communicate with the Teensy Audio Adapter from RPi. It was a problem with the 16-bit register addresses. I can send arbitrary-length arrays of bytes, though, and if I just send [reg-addr-MSB, reg-addr-LSB, value-MSB, value-LSB] it works!
I'm using the PLL of the SGTL5000, and a slightly different configuration from the default Teensy setup. And I have earphones full of loud, loud noise... with my audio mixed in there somewhere. Soundfiles are also playing back slowly, but I believe the answers to those I2S configuration issues will be easy to find online. For the time being, I have communicated with it and it's doing more or less what I tell it! I will write the whole procedure up if and when I get decent sound! Most DACs sold for Raspberry Pi are kind of steep, and they don't have ADC, and they're about the only ones with any kind of support. I'm glad I opted to get the Teensy Audio board and hack it!