AnsweredAssumed Answered

Problem with I2S interface: No clock on WS and SCK pins

Question asked by helene on Mar 13, 2015
Latest reply on Mar 19, 2015 by helene
Hi
I use a STM32L100C-DISCO kit.
I want to use I2S interface.
I configure this interface with STM32CubeMX:
I enable I2S2 as Half Duplex Master, I choose HSI and internal clocks to have an audio clock of 48kHz.
Everything seems OK and I generate a Keil project (for uVision5).
In this project, I try to do a polling I2S request, but unfortunately I never get clocks on SCK and WS pins. I look at these pins with an oscilloscope, but they are stucked at GND.

I send you my code :

/* Includes ------------------------------------------------------------------*/

#include "stm32l1xx_hal.h"

#include "stm32l100c_discovery.c"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

I2S_HandleTypeDef hi2s2;

  

/* USER CODE BEGIN PV */

  

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_I2S2_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

uint16_t RxBuffer[1024];

uint16_t Taille = 512;

uint32_t TimeOut = 1000;

/* USER CODE END 0 */

int main(void)

{

  

/* USER CODE BEGIN 1 */

  

/* USER CODE END 1 */

/* MCU Configuration----------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* Configure the system clock */

SystemClock_Config();

/* Initialize all configured peripherals */

MX_GPIO_Init();

 

BSP_LED_Init(LED3);

BSP_LED_Init(LED4);

 

MX_I2S2_Init();

 

/* USER CODE BEGIN 2 */

 

BSP_LED_On(LED4);

HAL_Delay(1000);

BSP_LED_Off(LED4);

 

 

if (HAL_I2S_Receive(&hi2s2, (uint16_t *) RxBuffer, Taille, TimeOut) == HAL_TIMEOUT)

{

BSP_LED_On(LED3);

HAL_Delay(1000);

BSP_LED_Off(LED3);

}

 

/* USER CODE END 2 */

/* USER CODE BEGIN 3 */

/* Infinite loop */

while (1)

{

BSP_LED_On(LED4);

HAL_Delay(500);

BSP_LED_Off(LED4);

HAL_Delay(500);

 

}

/* USER CODE END 3 */

}

/** System Clock Configuration

*/

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct;

RCC_ClkInitTypeDef RCC_ClkInitStruct;

__PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSICalibrationValue = 16;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;

RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;

HAL_RCC_OscConfig(&RCC_OscInitStruct);

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

__SYSCFG_CLK_ENABLE();

}

/* I2S2 init function */

void MX_I2S2_Init(void)

{

hi2s2.Instance = SPI2;

hi2s2.Init.Mode = I2S_MODE_MASTER_RX;

hi2s2.Init.Standard = I2S_STANDARD_PHILLIPS;

hi2s2.Init.DataFormat = I2S_DATAFORMAT_24B;

hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;

hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_48K;

hi2s2.Init.CPOL = I2S_CPOL_LOW;

if (HAL_I2S_Init(&hi2s2) == HAL_OK)

{

BSP_LED_On(LED3);

HAL_Delay(1000);

BSP_LED_Off(LED3);

}

}

/** Configure pins as

* Analog

* Input

* Output

* EVENT_OUT

* EXTI

*/

void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */

__GPIOC_CLK_ENABLE();

__GPIOH_CLK_ENABLE();

__GPIOA_CLK_ENABLE();

__GPIOB_CLK_ENABLE();

/*Configure GPIO pin : PA0 */

GPIO_InitStruct.Pin = GPIO_PIN_0;

GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/*Configure GPIO pins : PC8 PC9 */

GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;

HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

#ifdef USE_FULL_ASSERT

/**

* @brief Reports the name of the source file and the source line number

* where the assert_param error has occurred.

* @param file: pointer to the source file name

* @param line: assert_param error line source number

* @retval None

*/

void assert_failed(uint8_t* file, uint32_t line)

{

/* USER CODE BEGIN 6 */

/* User can add his own implementation to report the file name and line number,

ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

/* USER CODE END 6 */

}

#endif

Please can you help me?

Outcomes