AnsweredAssumed Answered

STM32F446 SAI Configuration StdPeriphLibrary

Question asked by xoroxo on Jun 15, 2016
Latest reply on Jun 27, 2016 by Amel N
Hello everyone.
I am a bit stuck with SAI configuration for STM32F446 MCU.
What I want to get is a full duplex SAI, working with PCM-coded signal coming from bluetooth module.

Now I am trying to configure the SAI bus. To do so I use StdPeripheral Drivers set.
First, I select the clock source for SAI and configure its frequency:
01.void PLLSAI_Config(void)
02.{
03.  /* Configure PLLI2S prescalers */
04.  /* PLLI2S_VCO : VCO_344M */
05.  /* SAI_CLK(first level) = PLLI2S_VCO/PLLI2SQ = 344/7 = 49.142 Mhz */
06.  RCC_PLLI2SConfig(16, 344, 2, 7, 2);
07.  /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ = 49.142/1 = 49.142 Mhz */
08.  RCC_SAIPLLI2SClkDivConfig(1);
09.  /* Configure Clock source for SAI */
10.  RCC_SAICLKConfig(RCC_SAIInstance_SAI1, RCC_SAICLKSource_PLLI2S);
11.  /* Enable PLLI2S Clock */
12.  RCC_PLLI2SCmd(ENABLE);
13.  /* Wait till PLLI2S is ready */
14.  while(RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY) == RESET)
15.  {
16.  }
17.  LOG_OUT("SAI clocks configured\n");
18.}

Second, I configure GPIO pins as alternate functions, no problem here.
Third configure SAI bus, enable the interrupts, enable SAI:
01.SAI_InitTypeDef tx_cfg =
02.{
03.    .SAI_Protocol = SAI_Free_Protocol,
04.    .SAI_AudioMode = SAI_Mode_MasterTx,
05.    .SAI_DataSize = SAI_DataSize_16b,
06.    .SAI_FirstBit = SAI_FirstBit_MSB,
07.    .SAI_ClockStrobing = SAI_ClockStrobing_RisingEdge,
08.    .SAI_Synchro = SAI_Asynchronous,
09.    .SAI_OUTDRIV = SAI_OutputDrive_Disabled,
10.    .SAI_NoDivider = SAI_MasterDivider_Enabled,
11.    .SAI_FIFOThreshold = SAI_FIFOThreshold_HalfFull,
12.};
13. 
14.SAI_InitTypeDef rx_cfg =
15.{
16.    .SAI_Protocol = SAI_Free_Protocol,
17.    .SAI_AudioMode = SAI_Mode_SlaveRx,
18.    .SAI_DataSize = SAI_DataSize_16b,
19.    .SAI_FirstBit = SAI_FirstBit_MSB,
20.    .SAI_ClockStrobing = SAI_ClockStrobing_RisingEdge,
21.    .SAI_Synchro = SAI_Synchronous,
22.    .SAI_OUTDRIV = SAI_OutputDrive_Disabled,
23.    .SAI_NoDivider = SAI_MasterDivider_Enabled,
24.    .SAI_FIFOThreshold = SAI_FIFOThreshold_HalfFull,
25.};
26. 
27.SAI_FrameInitTypeDef frame_cfg =
28.{
29.    .SAI_FrameLength = 16U * 2,
30.    .SAI_ActiveFrameLength = 1U,
31.    .SAI_FSDefinition = SAI_FS_StartFrame,
32.    .SAI_FSPolarity = SAI_FS_ActiveLow,
33.    .SAI_FSOffset = SAI_FS_BeforeFirstBit,
34.};
35. 
36.SAI_SlotInitTypeDef slot_cfg =
37.{
38.    .SAI_FirstBitOffset = 0U,
39.    .SAI_SlotSize = SAI_SlotSize_16b,
40.    .SAI_SlotNumber = 2,
41.    .SAI_SlotActive = SAI_SlotActive_ALL,
42.};
43. 
44.RCC_APB2PeriphClockCmd(RCC_APB2Periph_SAI1, ENABLE);
45. 
46.uint32_t tmpdiv = ((uint32_t)49152000) / (16000 * 512);
47.tx_cfg.SAI_MasterDivider = tmpdiv;
48.rx_cfg.SAI_MasterDivider = tmpdiv;
49. 
50.SAI_Init(SAI1_Block_A, &tx_cfg);
51.SAI_Init(SAI1_Block_B, &rx_cfg);
52.SAI_FrameInit(SAI1_Block_A, &frame_cfg);
53.SAI_FrameInit(SAI1_Block_B, &frame_cfg);
54.SAI_SlotInit(SAI1_Block_A, &slot_cfg);
55.SAI_SlotInit(SAI1_Block_B, &slot_cfg);
56. 
57.SAI_FlushFIFO(SAI1_Block_A);
58.SAI_FlushFIFO(SAI1_Block_B);
59. 
60.SAI_MonoModeConfig(SAI1_Block_A, SAI_MonoMode);
61.SAI_MonoModeConfig(SAI1_Block_B, SAI_MonoMode);
62. 
63.NVIC_SetPriority(SAI1_IRQn, 0);
64.NVIC_EnableIRQ(SAI1_IRQn);
65. 
66.uint32_t intsf = SAI_IT_FREQ | SAI_IT_OVRUDR | SAI_IT_AFSDET | SAI_IT_LFSDET | SAI_IT_CNRDY;
67.SAI_ITConfig(SAI1_Block_A, intsf, ENABLE);
68.SAI_ITConfig(SAI1_Block_B, intsf, ENABLE);
69. 
70.SAI_Cmd(SAI1_Block_A, ENABLE);
71.SAI_Cmd(SAI1_Block_B, ENABLE);

But then nothing happens, I don't have any interrupts or what is more strange I even don't have a clock on SCK pin of the MCU. Could someone give me any hints where to dig further? May be I messed up with configuration or clocks?
Thanks!

Outcomes