I2S clock reconfiguration error

sb_espressif
Posts: 28
Joined: Fri Dec 08, 2023 3:04 am

I2S clock reconfiguration error

Postby sb_espressif » Fri Jan 05, 2024 1:23 am

Hi;

I'm using IDF 5.1.2, compiling for an esp32-s3. My code reads a few bytes from an mp3 file in order to determine the file sample rate, and then I'd like to configure my I2S channel accordingly:

Code: Select all

    i2s_config.clk_cfg.sample_rate_hz = mp3_info.hz;
    i2s_channel_reconfig_std_clock(tx_handle, &i2s_config.clk_cfg);
When I run my code, I see this error:
E (2614) i2s_std: i2s_channel_reconfig_std_clock(264): this handle is not working in standard mode
though, oddly, I still hear sound. But I'd like to understand what I'm apparently doing wrong.

More thoroughly, my code looks like the following, which I cribbed mostly from the code on this page:
https://docs.espressif.com/projects/esp ... td-tx-mode

Code: Select all

   // ------------------------------
    // Set up I2S

    i2s_chan_handle_t tx_handle;

    // i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM, I2S_ROLE_MASTER);
    i2s_chan_config_t chan_cfg = {
        .id = I2S_NUM_0, // I2S port number
        .role = I2S_ROLE_MASTER, // Master role
        .dma_desc_num = 4, // Number of DMA descriptors
        .dma_frame_num = 1023, // Number of frames per DMA descriptor
        .auto_clear = true, // Auto clear on underflow
    };
    
    // Allocate a new TX channel and get the handle of this channel
    i2s_new_channel(&chan_cfg, &tx_handle, NULL);

    // Setting the configurations.
    // The slot configuration and clock configuration can be generated by the macros.
    // These two helper macros are defined in 'i2s_std.h' which can only be used in STD mode.
    // They can help to specify the slot and clock configurations for initialization or updating 
    i2s_std_config_t i2s_config = {
        .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
        .slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT,  I2S_SLOT_MODE_STEREO),
        .gpio_cfg = {
            .mclk = I2S_GPIO_UNUSED,
            .bclk = I2S_BCLK,
            .ws = I2S_WS,
            .dout = I2S_DO,
            .din = I2S_GPIO_UNUSED,
            .invert_flags = {
                .mclk_inv = false,
                .bclk_inv = false,
                .ws_inv = false,
            },
        },
    };

// ... determine sample rate from file...

   // Now that we've determined the sample rate of our file,
    // we can "reconfigure" our i2s channel accurately. 

    i2s_config.clk_cfg.sample_rate_hz = mp3_info.hz;
    i2s_channel_reconfig_std_clock(tx_handle, &i2s_config.clk_cfg);

    // Initialize the channel
    i2s_channel_init_std_mode(tx_handle, &i2s_config);

    // Enable the channel
    i2s_channel_enable(tx_handle);

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: I2S clock reconfiguration error

Postby MicroController » Fri Jan 05, 2024 1:54 pm

From the docs I take that you need to first initialize the channel (i2s_channel_init_std_mode(...)) and then you can reconfigure it via i2s_channel_reconfig_std_*. Or, since you're using the same configuration for reconfig and init anyway, just skip the reconfig and only init with these settings. (This is probably the reason why things work for you even though the reconfig failed.)

sb_espressif
Posts: 28
Joined: Fri Dec 08, 2023 3:04 am

Re: I2S clock reconfiguration error

Postby sb_espressif » Fri Jan 05, 2024 4:56 pm

Totally right! An oversight on my part, I had those two steps out of order. Thank you so very much!

Who is online

Users browsing this forum: No registered users and 99 guests