2021-12-23 04:22 AM
Hello,
I am trying to read sample from a AD7768 using a STM32F767. The data is feed to the SAI peripheral at 8Mhz. I used this code https://github.com/pavel-demin/stm32f7-discovery-usb-headset/blob/master/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_audio.c has reference.
I am reading sample in burst of few k bytes using the DMA. But approximately half the samples are wrongs. It looks like the first frame bit is read before the frame start which lead to a data frame shift of 1 bit. When it happens the bit LFSDET (Late frame synchronization detection) is set in the SR register. Sometime even if the data are correct the LFSDET bit is set.
I tried every frame synchronization and clock configuration but I cannot make it works. My best results are for [SAI_CLOCKSTROBING_FALLINGEDGE, SAI_FS_ACTIVE_HIGH, SAI_FS_BEFOREFIRSTBIT] and [SAI_CLOCKSTROBING_FALLINGEDGE, SAI_FS_ACTIVE_LOW SAI_FS_FIRSTBIT].
I use the following SAI initialization :
__HAL_RCC_SAI1_CLK_ENABLE();
_hsai1_a.Instance = SAI1_Block_A;
_hsai1_a.Init.Protocol = SAI_FREE_PROTOCOL;
_hsai1_a.Init.AudioMode = SAI_MODESLAVE_RX;
_hsai1_a.Init.DataSize = SAI_DATASIZE_32;
_hsai1_a.Init.FirstBit = SAI_FIRSTBIT_MSB;
_hsai1_a.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
_hsai1_a.Init.Synchro = SAI_ASYNCHRONOUS;
_hsai1_a.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
_hsai1_a.Init.NoDivider = SAI_MASTERDIVIDER_DISABLE;
_hsai1_a.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_FULL;
_hsai1_a.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
_hsai1_a.Init.MonoStereoMode = SAI_STEREOMODE;
_hsai1_a.Init.CompandingMode = SAI_NOCOMPANDING;
_hsai1_a.FrameInit.FrameLength = 128;
_hsai1_a.FrameInit.ActiveFrameLength = 1;
_hsai1_a.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
#if 0
_hsai1_a.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
_hsai1_a.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
#else
_hsai1_a.FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH;
_hsai1_a.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;
#endif
_hsai1_a.SlotInit.FirstBitOffset = 0;
_hsai1_a.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
_hsai1_a.SlotInit.SlotNumber = 4;
_hsai1_a.SlotInit.SlotActive = 0x0000FFFF;
if (HAL_SAI_Init(&_hsai1_a) != HAL_OK) {
//Error_Handler();
while(1);
}
Electrics signals are good.
The full driver code is in attachment, it used with the pseudo-code :
_ad7768.initalize();
while(1){
_ad7768.start(_buffer, _BUFFER_SIZE);
_ad7768.wait_for_receive_complete();
wait(1second);
}
I don't understand what is wrong with my setup. It looks like the FS signal is not detect as it should...
Did someone had the same problem ?
Do you have slave receiver code examples ?
Regards,
2023-05-29 01:44 AM
Hello, I am currently facing the same issue as you. Has this problem been resolved? Would you mind sharing the solution? Thank you.