Skip to content

I2S sampling freq not correct for 8-bit @ 8 kHz #310

Closed
@andrewjfox

Description

@andrewjfox

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,
logic_i2s_8khz_8bit

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions