This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to enable MCLK pin in NCS1.9.1 for I2S?

hello,

NCS1.9.1,  Windows10 X64,nRF5340-DK,nrfx_i2s

in file boards\nrf5340dk_nrf5340_cpuapp.overlay

    

i've i2s DAC model ,it must use 4 line(MCLK,SCLK,SDIN,LRCK)

but default config no MCLK pin set,i add mck-pin,it not work.

how to enable MCLK pin?

 

thanks

Best Regards

  • Hi,

    Could I see your prj.conf file, and how you are enabling the i2s peripheral in your code?

  • Hello,

    thanks for reply,  the file prj.conf

    i add [mck-pin = <0x26>;] to file boards\nrf5340dk_nrf5340_cpuapp.overlay

    i2s is master mode,i do't know how to enable MCLK.

    nrfx_err_t I2S_AUDIO_init()
    {
    	IRQ_DIRECT_CONNECT(I2S0_IRQn, 0, i2s_isr_handler, 0);
    	memset(&m_buffer_tx32u, 0x00, sizeof(m_buffer_tx32u));
    	memset(&m_buffer_rx32u, 0x00, sizeof(m_buffer_rx32u));
    	initial_buffers.p_tx_buffer = m_buffer_tx32u;
    	initial_buffers.p_rx_buffer = m_buffer_rx32u;
    
    	//YOu should probably change this config to fit your I2S microphone and audio preferences.
    	nrfx_i2s_config_t config =NRFX_I2S_DEFAULT_CONFIG(I2S_SCK_PIN, I2S_LRCK_PIN,
    								NRFX_I2S_PIN_NOT_USED,I2S_SDOUT_PIN, I2S_SDIN_PIN);
    
    	config.mode = NRF_I2S_MODE_MASTER;			
    	config.ratio = NRF_I2S_RATIO_96X;			
    	config.sample_width = NRF_I2S_SWIDTH_16BIT; 
    	config.mck_setup = NRF_I2S_MCK_32MDIV21;	//Preference     freq = (MCKfreq/ratio) =16.129 KHz.
    	config.channels = NRF_I2S_CHANNELS_LEFT;	
    
    	nrfx_err_t err_code = nrfx_i2s_init(&config, data_handler);
    	if (err_code != NRFX_SUCCESS)
    	{
    		printk("I2S init error\n");
    		return err_code;
    	}
    	err_code = nrfx_i2s_start(&initial_buffers, I2S_DATA_BLOCK_WORDS, 0); //start recording
    	if (err_code != NRFX_SUCCESS)
    	{
    		printk("I2S start error\n");
    		return err_code;
    	}
    	//nrfx_i2s_stop()
    
    	k_sleep(K_SECONDS(2));
    	return err_code;
    }

      

    thanks

    Best Regards

  • 	nrfx_i2s_config_t config =NRFX_I2S_DEFAULT_CONFIG(I2S_SCK_PIN, I2S_LRCK_PIN,
    								NRFX_I2S_PIN_NOT_USED,I2S_SDOUT_PIN, I2S_SDIN_PIN);

    Here you need to replace NRFX_I2S_PIN_NOT_USED with the MCK pin. If you don't already have a I2S_MCK_PIN, just define it the same way for example I2S_SCK_PIN is defined.

  • Hello,

    thanks a lot, i'm sorry,

    how could I not have noticed this line!

    Best Regards

Related