cancel
Showing results for 
Search instead for 
Did you mean: 

How can I disable a I2S module ?

tcg
Associate III

I am using cube mx for my design and I have some peripherals (ADC, Timer, I2S2, I2S3). I am making streaming by usb of some of them.

I want to stoop i2s modules when i am not using it becouse affect to other modules sampling rate.

By default Cubemx make this:

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_USART2_UART_Init();

 MX_TIM2_Init();

 MX_ADC1_Init();

 MX_TIM3_Init();

 MX_TIM1_Init();

 MX_I2S2_Init();

 MX_I2S3_Init();

 /* USER CODE BEGIN 2 */

And I am trying to make this

witch(mode_audio){

   case 1:

      HAL_TIM_Base_Start_IT(&htim2);

   break;

   case 2:

   __HAL_I2S_DISABLE(&hi2s2);

   __HAL_I2S_DISABLE(&hi2s3);

    HAL_ADC_Start_DMA(&hadc1, (uint32_t *)dmaBuffer, CH_BUFFERSIZE);

    HAL_TIM_OC_Start (&htim1,TIM_CHANNEL_1);

   case 3:

    // Inializate both DMA

    HAL_I2S_Receive_DMA(&hi2s2,(uint16_t *)data_i2s2,I2S_BUFFERSIZE);

    HAL_I2S_Receive_DMA(&hi2s3,(uint16_t *)data_i2s3,I2S_BUFFERSIZE);

   break;

but __HAL_I2S_DISABLE(&hi2s2); andHAL_I2S_DMAStop(&hi2s2) do not work.

Any idea. I want to stop the I2s module

Thanks for all kind regards, TC

7 REPLIES 7
tcg
Associate III

Hi again , that does not work

HAL_NVIC_DisableIRQ(DMA1_Stream3_IRQn);

HAL_NVIC_DisableIRQ(DMA1_Stream0_IRQn);

  __HAL_I2S_DISABLE(&hi2s2);

   __HAL_I2S_DISABLE(&hi2s3);

Which STM32?

What is "does not work"? What are exactly the symptoms, and how are they different from what you expect?

JW

tcg
Associate III

Hi, the problem it is that there i a overstress in the process and the output is not correctly genrate or both module write inide the ame buffer.


_legacyfs_online_stmicro_images_0693W00000biK7NQAU.png
_legacyfs_online_stmicro_images_0693W00000biK7SQAU.pngBoth module are writing in the same buffer so I2S is not stopped.

We can see that becouse hi and low signal are continuous. The higher part of the signal is from adc and the lower for i2s module. So I2S is not topped.

And this is the behaviour comment

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_USART2_UART_Init();

 MX_TIM2_Init();

 MX_ADC1_Init();

 MX_TIM3_Init();

 MX_TIM1_Init();

 //MX_I2S2_Init();

 // MX_I2S3_Init();


_legacyfs_online_stmicro_images_0693W00000biK8fQAE.png
_legacyfs_online_stmicro_images_0693W00000biJyRQAU.pngIn that case all signal came from ADC.

Thansk for your fast response.

tcg
Associate III

It is for Stm32F401

I don't quite understand what those pictures display.

Do you use I2S as receivers? Maybe you want to manually clear the I2S buffers after disabling them.

JW

tcg
Associate III

Ok, that pictures display 4 adc channel sampling at 48Khz for analog mics.

I can switch between I2S to Analog mics.

But if i use cubemx both modules are activated. Both DMA, from ADC (4channels) and for I2S3 and I2S2 tranfer info for same buffer.

If I stop I2S2 and I2S3 i think that only info form ADC dma must be transfer by streaming to pc.

I am using

HAL_NVIC_DisableIRQ(DMA1_Stream3_IRQn);

HAL_NVIC_DisableIRQ(DMA1_Stream0_IRQn);

for stop the DMA and

  __HAL_I2S_DISABLE(&hi2s2);

  __HAL_I2S_DISABLE(&hi2s3);

for stop the module and they did not stop. I can know this becoue a break point is in the DMA interrupt for I2S2 and I2S3 transfer and it stop there.

void DMA1_Stream0_IRQHandler(void)

{

 /* USER CODE BEGIN DMA1_Stream0_IRQn 0 */

 /* USER CODE END DMA1_Stream0_IRQn 0 */

 HAL_DMA_IRQHandler(&hdma_spi3_rx);

 /* USER CODE BEGIN DMA1_Stream0_IRQn 1 */

 /* USER CODE END DMA1_Stream0_IRQn 1 */

}

/**

 * @brief This function handles DMA1 stream3 global interrupt.

 */

void DMA1_Stream3_IRQHandler(void)

{

 /* USER CODE BEGIN DMA1_Stream3_IRQn 0 */

 /* USER CODE END DMA1_Stream3_IRQn 0 */

 HAL_DMA_IRQHandler(&hdma_spi2_rx);

 /* USER CODE BEGIN DMA1_Stream3_IRQn 1 */

 /* USER CODE END DMA1_Stream3_IRQn 1 */

}

I try to use

#define __HAL_I2S_DISABLE( __HANDLE__)   ((__HANDLE__)->Instance->I2SCFGR &=(uint16_t)(~SPI_I2SCFGR_I2SE))

I supposed that DMA must be stopped before stop I2S module but that not works.

This could be other option.

#define __HAL_I2S_DISABLE_IT( __HANDLE__, __INTERRUPT__ )   ((__HANDLE__)->Instance->CR2 &=(uint16_t)(~(__INTERRUPT__)))

But this option allow disable the interrupt but the module will be actived unnecessarily.

Could you suggest what would you do if you wanted to stop module I2S2 started by cubemx? 

I know the logical thing to do is not to initialise it but I don't want to delete the cubemx configuration to keep the ioc file as documentation.I deactivate the modules within the code.

If all works well, the buffer should be overwritten by the adc's DMA, since it only has 192 samples 48*4 with a conversion trigger frequency through tim1 every 1/1khz

In fact when I comment on the Cubemx startup for is2 and i2s3 everything works as expected as shown in the graphs in the previous post.

 Yes I2S2 modules works as reciver.

Kind regards, TC

FBL
ST Employee

Hello @Tomás Cabeza​,

Have you tried to disable it using HAL_I2S_DMAStop() or HAL_I2S_DeInit(). This could be other option worth to try.

Hope this helps!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.