Description
Hi,
I've been trying to get audio from a modem using the I2S/PCM interface and having some troubles getting accurate clock frequencies.
I'm trying to read single 16bit words from modem @ 8kHz, by configuring the I2S as 8bit slots, since I see in the library it's expecting stereo so has min 2 slots. Following is code to init device, note that I am adjusting clock polarity and FS width to suit modem.
I2S.onReceive(ISR_onI2SReceive);
if(!I2S.begin(I2S_PHILIPS_MODE, 8000, 8)) return false;
/* SAMD21 I2S peripheral samples data on +ve clock edge, however modem data is valid on -ve edge
* if SAMD is master then can invert output clock, this only changes output, so internal operation is unchanged
* modem requires FS to be 1 bit width (in slave mode)
*/
i2s_disable();
REG_I2S_CLKCTRL0 &= ~I2S_CLKCTRL_FSWIDTH_Msk; //clear FS width
REG_I2S_CLKCTRL0 |= I2S_CLKCTRL_SCKOUTINV | (I2S_CLKCTRL_FSWIDTH_BIT_Val << I2S_CLKCTRL_FSWIDTH_Pos); //invert clock output, FS 1 bit wide (TDM mode)
i2s_enable();
For this setup, with 8kHz sample rate I would expect SCLK to be 8000 * 2 * 8 = 128kHz, however when I monitor the I2S lines using logic analyser, the clock is around 400kHz, and FS is around 25kHz. See attached screen capture,
If I have it configured for 8kHz and 16bit data, then clock and frame are at 256kHz and 8kHz resepctively, as expected.
I had a look at the driver code but the clock setting is a bit complex at first glance so wasn't really able to locate where the issue is.
Regards
Andrew