Creating I2S TX and RX channels on two I2S ports

Al_daespexplorer
Posts: 2
Joined: Thu Nov 02, 2023 3:12 am

Creating I2S TX and RX channels on two I2S ports

Postby Al_daespexplorer » Sun May 26, 2024 9:19 pm

I'm facing an issue with I2S Simplex mode on the ESP32S3, specifically when configuring two I2S ports for RX and TX separately. According to the documentation, this setup should be feasible. When I configure only the RX port, it functions correctly. However, upon adding and setting up the TX port, the i2s_channel_read(.) function only returns zeros from the RX channel.

I'm unsure about the correctness of my pin setup, as the documentation does not clarify whether using a common bclk and ws pins for simplex mode is permissible. This setup is necessary due to my custom PCB design. Below are the relevant code segments:

Separate I2S config macros for Tx and RX:
  1. #define I2S_CONFIG_DEFAULT_RX(sample_rate, channel_fmt, bits_per_chan) { \
  2.         .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(sample_rate), \
  3.         .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(bits_per_chan, channel_fmt), \
  4.         .gpio_cfg = { \
  5.             .mclk = GPIO_NUM_NC, \
  6.             .bclk = GPIO_I2S_SCLK, \
  7.             .ws   = GPIO_I2S_LRCK, \
  8.             .dout = GPIO_NUM_NC, \
  9.             .din  = GPIO_I2S_SDIN, \
  10.             .invert_flags = { \
  11.                 .mclk_inv = false, \
  12.                 .bclk_inv = false, \
  13.                 .ws_inv   = false, \
  14.             }, \
  15.         }, \
  16.     }
  17.  
  18. #define I2S_CONFIG_DEFAULT_TX(sample_rate, channel_fmt, bits_per_chan) { \
  19.         .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(sample_rate), \
  20.         .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(bits_per_chan, channel_fmt), \
  21.         .gpio_cfg = { \
  22.             .mclk = GPIO_NUM_NC, \
  23.             .bclk = GPIO_I2S_SCLK, \
  24.             .ws   = GPIO_I2S_LRCK, \
  25.             .dout = GPIO_I2S_DOUT, \
  26.             .din  = GPIO_NUM_NC, \
  27.             .invert_flags = { \
  28.                 .mclk_inv = false, \
  29.                 .bclk_inv = false, \
  30.                 .ws_inv   = false, \
  31.             }, \
  32.         }, \
  33.     }
RX and TX channel definition and initialization]:
  1. static esp_err_t bsp_i2s_init_microphone(i2s_port_t i2s_num, uint32_t sample_rate, i2s_slot_mode_t channel_format, i2s_data_bit_width_t bits_per_chan)
  2. {
  3.     esp_err_t ret_val = ESP_OK;
  4.  
  5.     i2s_chan_config_t rx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(i2s_num, I2S_ROLE_MASTER);
  6.     ret_val |= i2s_new_channel(&rx_chan_cfg, NULL, &rxHandle);
  7.     i2s_std_config_t rx_std_cfg = I2S_CONFIG_DEFAULT_RX(sample_rate, channel_format, bits_per_chan);
  8.  
  9. rx_std_cfg.slot_cfg.slot_mask = I2S_STD_SLOT_BOTH;
  10. rx_std_cfg.clk_cfg.mclk_multiple = (i2s_mclk_multiple_t) (I2S_MCLK_MULTIPLE_384);
  11.  
  12. ret_val |= i2s_channel_init_std_mode(rxHandle, &rx_std_cfg);
  13.     ret_val |= i2s_channel_enable(rxHandle);
  14.  
  15.     return ret_val;
  16. }
  17.  
  18. static esp_err_t bsp_i2s_init_speaker(i2s_port_t i2s_num, uint32_t sample_rate, i2s_slot_mode_t channel_format, i2s_data_bit_width_t bits_per_chan)
  19. {
  20.     esp_err_t ret_val = ESP_OK;
  21.  
  22.     i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(i2s_num, I2S_ROLE_SLAVE);
  23.     ret_val |= i2s_new_channel(&tx_chan_cfg, &txHandle, NULL);
  24.  
  25.     i2s_std_config_t tx_std_cfg = I2S_CONFIG_DEFAULT_TX(sample_rate, channel_format, bits_per_chan);
  26.     // speaker is set to mono
  27.     tx_std_cfg.slot_cfg.slot_mask = I2S_STD_SLOT_RIGHT;
  28.  
  29.     ret_val |= i2s_channel_init_std_mode(txHandle, &tx_std_cfg);
  30.  
  31.     return ret_val;
  32. }
And how I call them in the pp function:
  1. void app_main(void)
  2. {
  3. .
  4. .
  5. .
  6.     err = bsp_i2s_init_microphone(I2S_NUM_1, 16000, I2S_SLOT_MODE_STEREO, I2S_DATA_BIT_WIDTH_32BIT);
  7.  
  8.     err = bsp_i2s_init_speaker(I2S_NUM_0, 16000, I2S_SLOT_MODE_MONO, I2S_DATA_BIT_WIDTH_16BIT);
  9. .
  10. .
  11. .
  12.  
  13. }
Could someone clarify whether my configuration is correct or provide guidance on what might be going wrong?

Who is online

Users browsing this forum: No registered users and 97 guests