cancel
Showing results for 
Search instead for 
Did you mean: 

source: en.fp-aud-bvlinkwb2.zip I want to output the Central's USB output to the codec chip (sgtl5000) through the SAI interface.

bjh3482
Associate

Voice is heard through the codec chip, but the noise is severe.

There is no noise when you listen to the voice from the PC through the USB output.

I don't know if the SAI setting on the Central is wrong or the codec chip setting is wrong. If you playback the wave file on the codec chip, there is no noise.

void Playback_Init(void)

{

 /* Configure and enable PLLSAI1 clock to generate 11.294MHz */

 RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct;

 RCC_PeriphCLKInitStruct.PeriphClockSelection  = RCC_PERIPHCLK_SAI1;

 RCC_PeriphCLKInitStruct.PLLSAI1.PLLN    = 24;

 RCC_PeriphCLKInitStruct.PLLSAI1.PLLP    = 17;

 RCC_PeriphCLKInitStruct.Sai1ClockSelection   = RCC_SAI1CLKSOURCE_PLLSAI1;

 if(HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /* Initialize SAI */

 __HAL_SAI_RESET_HANDLE_STATE(&SaiHandle);

 SaiHandle.Instance = AUDIO_SAIx;

 __HAL_SAI_DISABLE(&SaiHandle);

 SaiHandle.Init.AudioMode   = SAI_MODEMASTER_TX;

 SaiHandle.Init.Synchro    = SAI_ASYNCHRONOUS;

 SaiHandle.Init.OutputDrive  = SAI_OUTPUTDRIVE_ENABLE;

 SaiHandle.Init.NoDivider   = SAI_MASTERDIVIDER_ENABLE;

 SaiHandle.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;

 SaiHandle.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_16K;

 SaiHandle.Init.Protocol    = SAI_FREE_PROTOCOL;

 SaiHandle.Init.DataSize    = SAI_DATASIZE_16;

 SaiHandle.Init.FirstBit    = SAI_FIRSTBIT_MSB;

 SaiHandle.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;

 SaiHandle.Init.SynchroExt   = SAI_SYNCEXT_DISABLE;

 SaiHandle.Init.Mckdiv     = 0; /* N.U */

 SaiHandle.Init.MonoStereoMode = SAI_STEREOMODE;

 SaiHandle.Init.CompandingMode = SAI_NOCOMPANDING;

 SaiHandle.Init.TriState    = SAI_OUTPUT_NOTRELEASED;

 SaiHandle.FrameInit.FrameLength    = 32;

 SaiHandle.FrameInit.ActiveFrameLength = 1;

 SaiHandle.FrameInit.FSDefinition   = SAI_FS_CHANNEL_IDENTIFICATION;

 SaiHandle.FrameInit.FSPolarity    = SAI_FS_ACTIVE_LOW;

 SaiHandle.FrameInit.FSOffset     = SAI_FS_BEFOREFIRSTBIT;

 SaiHandle.SlotInit.FirstBitOffset = 0;

 SaiHandle.SlotInit.SlotSize    = SAI_SLOTSIZE_DATASIZE;

 SaiHandle.SlotInit.SlotNumber   = 2;

 SaiHandle.SlotInit.SlotActive   = (SAI_SLOTACTIVE_0 | SAI_SLOTACTIVE_1);

 if(HAL_OK != HAL_SAI_Init(&SaiHandle))

 {

  Error_Handler();

 }

 /* Enable SAI to generate clock used by audio driver */

 __HAL_SAI_ENABLE(&SaiHandle);

 /* Initialize audio driver */

 readID = sgtl5000_drv.ReadID(AUDIO_I2C_ADDRESS)>>8;

 if(SGTL50000_ID != (sgtl5000_drv.ReadID(AUDIO_I2C_ADDRESS)>>8))

 {

  Error_Handler();

 }

 audio_drv = &sgtl5000_drv;

 audio_drv->Reset(AUDIO_I2C_ADDRESS);

 if(0 != audio_drv->Init(AUDIO_I2C_ADDRESS, 0x02, 80, 22050))

 {

  Error_Handler();

 }

 /* Start the playback */

 if(0 != audio_drv->Play(AUDIO_I2C_ADDRESS))

 {

  Error_Handler();

 }

 if(HAL_OK != HAL_SAI_Transmit_DMA(&SaiHandle, (uint8_t *)PlayBuff, PLAY_BUFF_SIZE))

 {

  Error_Handler();

 }

}

0 REPLIES 0