cancel
Showing results for 
Search instead for 
Did you mean: 

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

helene
Associate II
Posted on March 13, 2015 at 10:47

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 ------------------------------------------------------------------*/

&sharpinclude ''stm32l1xx_hal.h''

&sharpinclude ''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 */

&sharpifdef 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 */

}

&sharpendif

Please can you help me?

#discovery #i2s
3 REPLIES 3
raptorhal2
Lead
Posted on March 14, 2015 at 16:51

I don't see any initialization of PB12 and PB13 as Alternate Function 5.

Regards, Hal

helene
Associate II
Posted on March 16, 2015 at 15:50

Hal

Thank you for your answer.

Initialization of PB12 and PB13 is done in HAL_I2S_MspInit (called by HAL_I2S_Init).

Here is the code :

void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  if(hi2s->Instance==SPI2)

  {

  /* USER CODE BEGIN SPI2_MspInit 0 */

  /* USER CODE END SPI2_MspInit 0 */

    /* Peripheral clock enable */

    __SPI1_CLK_ENABLE();

 

    /**I2S2 GPIO Configuration   

    PB12     ------> I2S2_WS

    PB13     ------> I2S2_CK

    PB15     ------> I2S2_SD

    */

    GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_15;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;

    GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* USER CODE BEGIN SPI2_MspInit 1 */

  /* USER CODE END SPI2_MspInit 1 */

  }

}

I really don't know what's wrong. I changed the speed (from very low to high) but it's not better. 

Regards, Helene 

helene
Associate II
Posted on March 19, 2015 at 08:30

I found the solution : I add

__SPI2_CLK_ENABLE();

in HAL_I2S_MspInit, instead of __SPI1_CLK_ENABLE();

It was not the good peripheral clock which was enabled.

It is a bug from STM32CubeMX.

Helene