How to stop I2S peripheral correctly

accacca
Posts: 40
Joined: Mon Aug 06, 2018 4:59 pm

How to stop I2S peripheral correctly

Postby accacca » Fri Nov 21, 2025 7:10 am

I am trying to create an RTSP server with video/audio streaming. When I close the client side and stop the I2S streaming, I get many error messages in the serial debug window.
What is the correct way to close the I2S peripheral?
My close function

Code: Select all

static esp_err_t app_audio_deinit()
{
  if (audio == NULL) return ESP_OK ;
  
  app_audio_g711_deinit() ; 
 ESP_LOGI (TAG, "esp_codec_dev_close start") ;
  esp_err_t ret = esp_codec_dev_close(audio->play_dev);
  //if (ret != ESP_OK) return ESP_FAIL ;
 ESP_LOGI (TAG, "esp_codec_dev_close end - play") ;
  ret = esp_codec_dev_close(audio->record_dev);
 // if (ret != ESP_OK) return ESP_FAIL ;
 ESP_LOGI (TAG, "esp_codec_dev_close end - rec") ;
 
  esp_codec_dev_delete(audio->play_dev);
  esp_codec_dev_delete(audio->record_dev);
  
  // Delete codec interface
  audio_codec_delete_codec_if(audio->in_codec_if);
  audio_codec_delete_codec_if(audio->out_codec_if);
  
  // Delete codec control interface
  audio_codec_delete_ctrl_if(audio->in_ctrl_if);
  audio_codec_delete_ctrl_if(audio->out_ctrl_if);
  audio_codec_delete_gpio_if(audio->gpio_if);
  
  // Delete codec data interface
  audio_codec_delete_data_if(audio->data_if);
  
  app_audio_i2s_deinit(I2S_NUM);
  app_audio_i2c_deinit(I2C_PORT);

  free(audio) ;
  audio = NULL ;

  return ESP_OK ;
}



I receive a lot of this errors:

Code: Select all

 (18995) APP_AUDIO: esp_codec_dev_close start
I (19005) ESP_RTSP_SERVER: Video send thread exited
E (19095) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (19095) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (19095) I2C_If: Fail to write to dev 30
E (19205) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (19205) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (19205) I2C_If: Fail to write to dev 30
E (19315) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
.......
.......
E (20635) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (20635) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (20635) I2C_If: Fail to write to dev 30
I (20645) I2S_IF: Pending out channel for in channel running
flollowed by this errors

Code: Select all

I (20645) APP_AUDIO: esp_codec_dev_close end - play
E (20755) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (20755) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (20755) I2C_If: Fail to write to dev 80
E (20865) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (20865) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (20865) I2C_If: Fail to write to dev 80
............
...........
........... 
E (21415) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (21415) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (21415) I2C_If: Fail to write to dev 80
E (21525) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (21525) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (21525) I2C_If: Fail to write to dev 80
E (21635) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (21635) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (21635) I2C_If: Fail to write to dev 80
I (21645) APP_AUDIO: esp_codec_dev_close end - rec

and the error list therminate with

Code: Select all

E (24275) i2c.master: s_i2c_synchronous_transaction(918): I2C transaction failed
E (24275) i2c.master: i2c_master_multi_buffer_transmit(1180): I2C transaction failed
E (24275) I2C_If: Fail to write to dev 30
E (24285) i2s_common: i2s_channel_disable(1187): the channel has not been enabled yet
E (24295) i2s_common: i2s_channel_disable(1187): the channel has not been enabled yet

lichurbagan
Posts: 59
Joined: Thu Nov 13, 2025 3:20 pm

Re: How to stop I2S peripheral correctly

Postby lichurbagan » Fri Nov 21, 2025 3:09 pm

You did NOT stop audio tasks before closing. You should stop RTSP audio reading / writing before shutting down I2S.

Who is online

Users browsing this forum: Baidu [Spider], ChatGPT-User, PetalBot and 9 guests