I2S Master Clock always runs at same speed as Bit Clock

Hi,

I have used the I2S echo sample project as a starting point and try to configure it to sample data from an I2S microphone running on the nRF5340.

However, I cannot get the I2S Master Clock to run at a multiple of the Bit Clock. There doesn't seem to be any configuration related to master clock setting in i2s_config.

I have verified that the Bit Clock and LR Clock runs at the expected frequencies using a logic analyser and observe that the Master Clock runs the same as Bit Clock...

Can someone please point me in the right direction for what I am missing?

Kind regards,

Steinar Thon

Here is my code to setup and start the I2S interface:

#include <zephyr/drivers/i2s.h>

#define SAMPLE_FREQUENCY    (48000)
#define SAMPLES_PER_BLOCK   (96)
#define SAMPLE_BIT_WIDTH    (32)
#define BYTES_PER_SAMPLE    (4)
#define NUMBER_OF_CHANNELS  (2)

#define TIMEOUT             (1000)

#define I2S_RX_NODE  DT_NODELABEL(i2s_rxtx)

#define BLOCK_COUNT (16)
#define BLOCK_SIZE  (BYTES_PER_SAMPLE * SAMPLES_PER_BLOCK * NUMBER_OF_CHANNELS)
K_MEM_SLAB_DEFINE_STATIC(mem_slab, BLOCK_SIZE, BLOCK_COUNT, BLOCK_COUNT);

static const struct device *const i2s_dev_rx = DEVICE_DT_GET(I2S_RX_NODE);

static bool i2s_init(void)
{
	struct i2s_config config;

	if (!device_is_ready(i2s_dev_rx))
	{
		printk("%s is not ready\n", i2s_dev_rx->name);
		return 0;
	}
	
	config.word_size = SAMPLE_BIT_WIDTH;
	config.channels = NUMBER_OF_CHANNELS;
	config.format = I2S_FMT_DATA_FORMAT_I2S;
	config.options = I2S_OPT_BIT_CLK_MASTER | I2S_OPT_FRAME_CLK_MASTER;
	config.frame_clk_freq = SAMPLE_FREQUENCY;
	config.mem_slab = &mem_slab;
	config.block_size = BLOCK_SIZE;
	config.timeout = TIMEOUT;

	int ret = i2s_configure(i2s_dev_rx, I2S_DIR_RX, &config);

	if (ret < 0)
	{
		printk("Failed to configure RX stream: %d\n", ret);
		return false;
	}

	ret = i2s_trigger(i2s_dev_rx, I2S_DIR_RX, I2S_TRIGGER_START);
		
	if (ret < 0)
	{
		printk("Failed to trigger command I2S_TRIGGER_START on RX: %d\n", ret);
		return false;
	}
	return true;
}

Here is the overlay to configure the I2S interface and pinout:

&pinctrl {

	i2s0_default_alt: i2s0_default_alt {
		group1 {
			// I2S Mic 
			psels = <NRF_PSEL(I2S_SCK_M, 0, 27)>,
				<NRF_PSEL(I2S_MCK, 1, 10)>,
				<NRF_PSEL(I2S_LRCK_M, 1, 3)>,
				<NRF_PSEL(I2S_SDIN, 1, 2)>;
		};
	};
};

&clock {
	hfclkaudio-frequency = <12288000>;
};

i2s_rxtx: &i2s0 {
	status = "okay";
	pinctrl-0 = <&i2s0_default_alt>;
	pinctrl-names = "default";
	clock-source = "ACLK";
};

Parents
  • Hello Steinar,

    Thank you for your patience with this.

    From the nRF5340 I2S documentation we have that:

    LRCK = MCK / CONFIG.RATIO

    and

    The serial clock (SCK), often referred to as the serial bit clock, pulses once for each data bit being transferred on the serial data lines SDIN and SDOUT.

    When operating in Master mode, the SCK is generated from the MCK, and the frequency of SCK is then given as:
    SCK = 2 * LRCK * CONFIG.SWIDTH 


    I do not however see that this should produce a SCK equal to the MCK in your case. Could you possibly share the oscilloscope traces so that I could have a look?

    I also notice that you are not setting the mck_setup explicitly - could you try this, and see if it then achieves the mck frequency you were intending?

    Best regards,
    Karl

Reply
  • Hello Steinar,

    Thank you for your patience with this.

    From the nRF5340 I2S documentation we have that:

    LRCK = MCK / CONFIG.RATIO

    and

    The serial clock (SCK), often referred to as the serial bit clock, pulses once for each data bit being transferred on the serial data lines SDIN and SDOUT.

    When operating in Master mode, the SCK is generated from the MCK, and the frequency of SCK is then given as:
    SCK = 2 * LRCK * CONFIG.SWIDTH 


    I do not however see that this should produce a SCK equal to the MCK in your case. Could you possibly share the oscilloscope traces so that I could have a look?

    I also notice that you are not setting the mck_setup explicitly - could you try this, and see if it then achieves the mck frequency you were intending?

    Best regards,
    Karl

Children
No Data
Related