2022-09-26 02:09 AM
As you can see the CH2(blue) is triggers 8 time asynchronous to transmission CH1(yellow). Why this happen since fifo threshold is empty?
The code:
while (1)
{
for(uint8_t i=0;i<7;i++)
{
while(hsai_BlockA2.State != HAL_SAI_STATE_READY);
HAL_SAI_Transmit_IT(&hsai_BlockA2, (uint8_t*)&noisebuf[0], 1);
}
for(uint8_t i=0;i<20;i++)
{
while(hsai_BlockB2.State != HAL_SAI_STATE_READY);
HAL_SAI_Receive_IT(&hsai_BlockB2, (uint8_t*)&adcbuf[0], 1);
}
HAL_Delay(5);
}
static void MX_SAI2_Init(void)
{
hsai_BlockA2.Instance = SAI2_Block_A;
hsai_BlockA2.Init.AudioMode = SAI_MODEMASTER_TX;
hsai_BlockA2.Init.Synchro = SAI_ASYNCHRONOUS;
hsai_BlockA2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockA2.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
hsai_BlockA2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
hsai_BlockA2.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_8K;
hsai_BlockA2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockA2.Init.MonoStereoMode = SAI_MONOMODE;
hsai_BlockA2.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockA2.Init.TriState = SAI_OUTPUT_RELEASED;
if (HAL_SAI_InitProtocol(&hsai_BlockA2, SAI_I2S_STANDARD, SAI_PROTOCOL_DATASIZE_16BITEXTENDED, 2) != HAL_OK)
{
Error_Handler();
}
hsai_BlockB2.Instance = SAI2_Block_B;
hsai_BlockB2.Init.AudioMode = SAI_MODESLAVE_RX;
hsai_BlockB2.Init.Synchro = SAI_SYNCHRONOUS;
hsai_BlockB2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockB2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
hsai_BlockB2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockB2.Init.MonoStereoMode = SAI_MONOMODE;
hsai_BlockB2.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockB2.Init.TriState = SAI_OUTPUT_RELEASED;
if (HAL_SAI_InitProtocol(&hsai_BlockB2, SAI_I2S_STANDARD, SAI_PROTOCOL_DATASIZE_16BITEXTENDED, 2) != HAL_OK)
{
Error_Handler();
}
}
void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
{
HAL_GPIO_TogglePin(test1_GPIO_Port, test1_Pin);
}
void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai)
{
HAL_GPIO_TogglePin(test_GPIO_Port, test_Pin);
}
By changing receiver FIFO threshold to Full the graph is now symmetrical, But what happened, could someone explain?
And by inserting
SET_BIT((&hsai_BlockB2)->Instance->CR2, SAI_xCR2_FFLUSH);
before Rx for loop the shapes also improves!