cancel
Showing results for 
Search instead for 
Did you mean: 

How to initialize the audio codec cs42l51-cnz with standby mode in cortex-M4 of STM32mp157A-DK1 ?

June1
Associate II

I want to do audio recording an cm4,but dont know how to config the codec,  Is there an audio recorder example? 

2 REPLIES 2
mleo
Senior II

Hello @浩 张​ ,

There's no such example for STM32MP1 but this audio codec is used on L4 discovery board, see:

https://www.st.com/resource/en/user_manual/dm00353127-discovery-kit-with-stm32l496ag-mcu-stmicroelectronics.pdf

You can reuse the code from the audio example in STM32L4Cube.

Hope this helps

Best regards,

Milan

June1
Associate II

when setting audio via I2C1, I always got NACK on the bus. I have checked AD0=0 , and guess it is the audio codec not ready, how can I resolve this issue?

AUDIO_I2C_ADDRESS= 0x94

 0693W000004Gg5LQAS.png

void AUDIO_IO_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct;
  uint8_t Value, ret;
 
 
  /* Enable Reset GPIO Clock */
  AUDIO_RESET_GPIO_CLK_ENABLE();
 
  /* Audio reset pin configuration */
  GPIO_InitStruct.Pin   = AUDIO_RESET_PIN;
  GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  GPIO_InitStruct.Pull  = GPIO_PULLUP;//GPIO_NOPULL;
  HAL_GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStruct);
//OK
 
  /* I2C bus init */
  I2C1_Init();
 
  /* Power off the codec */
  CODEC_AUDIO_POWER_OFF();
  ret = HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_9);
  printf("ret1= %d\n",ret);
 
  /* wait until power supplies are stable */
  HAL_Delay(10);
 
  /* Power on the codec */
  CODEC_AUDIO_POWER_ON();
  ret = HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_9);
  printf("ret2= %d\n",ret);
 
//  if(HAL_I2C_IsDeviceReady(&I2c1Handle, AUDIO_I2C_ADDRESS, 3, 3000)!=HAL_OK){
//	  printf("device not ready!\n\n");
//  }
 
  /* Set the device in standby mode */
  Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x02);
  AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x02, (Value | 0x01));
 
  /* Set all power down bits to 1 */
  AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x02, 0x7F);
  Value = AUDIO_IO_Read(AUDIO_I2C_ADDRESS, 0x03);
  AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x03, (Value | 0x0E));
}

Thanks