2022-09-29 07:45 AM
Hi,
I have STM32H743Z and ADC converter AD7771. I want to use SAI interface for reading data from it. I have configured AD7771, that results form conversions are sent over DOUT_0 line. In oscilloscope I can see line DRDY (falling edge), line DOUT0 sends some data (do not have SAI decoder) and CLK for clock. I connected ADC like that: SAI3_FS->DRDY, SAI3_SD->DOUT0, SAI3_SCK to DCLK.
output data should be in this format (I use 8 ADC channels)
I configured SAI like that:
hsai_BlockB3.Instance = SAI3_Block_B;
hsai_BlockB3.Init.Protocol = SAI_FREE_PROTOCOL;
hsai_BlockB3.Init.AudioMode = SAI_MODESLAVE_RX;
hsai_BlockB3.Init.DataSize = SAI_DATASIZE_8;
hsai_BlockB3.Init.FirstBit = SAI_FIRSTBIT_MSB;
hsai_BlockB3.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
hsai_BlockB3.Init.Synchro = SAI_ASYNCHRONOUS;
hsai_BlockB3.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockB3.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
hsai_BlockB3.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockB3.Init.MonoStereoMode = SAI_STEREOMODE;
hsai_BlockB3.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockB3.Init.TriState = SAI_OUTPUT_NOTRELEASED;
hsai_BlockB3.Init.PdmInit.Activation = DISABLE;
hsai_BlockB3.Init.PdmInit.MicPairsNbr = 1;
hsai_BlockB3.Init.PdmInit.ClockEnable = SAI_PDM_CLOCK1_ENABLE;
hsai_BlockB3.FrameInit.FrameLength = 256;
hsai_BlockB3.FrameInit.ActiveFrameLength = 1;
hsai_BlockB3.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
hsai_BlockB3.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
hsai_BlockB3.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
hsai_BlockB3.SlotInit.FirstBitOffset = 0;
hsai_BlockB3.SlotInit.SlotSize = SAI_SLOTSIZE_32B;
hsai_BlockB3.SlotInit.SlotNumber = 1;
hsai_BlockB3.SlotInit.SlotActive = 0x00000000;
Problem is that if I call HAL_SAI_Receive(&hsai_BlockB3, Buffer, 4, 0xffffff); so nothing is recieved.
What I missed? Where could be a problem?
Thank you very much, Jan.
2022-10-05 01:51 PM
hsai_BlockB3.SlotInit.SlotActive = 0x00000000;
You have not enabled any slot.
2022-10-05 10:26 PM
Yes I know, becase I am not sure hot to set up it:
(I want to read all 8 channels on 1 line DOUT_0)). 1 ADC channel has 4 bytes (1 for header an 3 for ADC data)
I want to use SAI interface. I tried to read data like that, but there are some weird data HAL_SAI_Receive(&hsai_BlockB3,(uint8_t *) GlSAI_DMA_Buff, 8, 0xffffff);
What I am not sure about is:
2022-10-07 05:55 AM
OK, so this config works to me I can read 4 channels, not sure how to read all 8 channels:
What is the DataSize, SlotSize,SlotNumber and SlotActive - I do not really understnad it!
hsai_BlockB3.Instance = SAI3_Block_B;
hsai_BlockB3.Init.Protocol = SAI_FREE_PROTOCOL;
hsai_BlockB3.Init.AudioMode = SAI_MODESLAVE_RX;
hsai_BlockB3.Init.DataSize = SAI_DATASIZE_8;
hsai_BlockB3.Init.FirstBit = SAI_FIRSTBIT_MSB;
hsai_BlockB3.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
hsai_BlockB3.Init.Synchro = SAI_ASYNCHRONOUS;
hsai_BlockB3.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockB3.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
hsai_BlockB3.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockB3.Init.MonoStereoMode = SAI_STEREOMODE;
hsai_BlockB3.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockB3.Init.TriState = SAI_OUTPUT_NOTRELEASED;
hsai_BlockB3.Init.PdmInit.Activation = DISABLE;
hsai_BlockB3.Init.PdmInit.MicPairsNbr = 0;
hsai_BlockB3.Init.PdmInit.ClockEnable = SAI_PDM_CLOCK1_ENABLE; //dat nulu
hsai_BlockB3.FrameInit.FrameLength = 256;
hsai_BlockB3.FrameInit.ActiveFrameLength = 128;
hsai_BlockB3.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
hsai_BlockB3.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
hsai_BlockB3.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
hsai_BlockB3.SlotInit.FirstBitOffset = 0;
hsai_BlockB3.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
hsai_BlockB3.SlotInit.SlotNumber = 32;
hsai_BlockB3.SlotInit.SlotActive = SAI_SLOTACTIVE_ALL;
2022-10-19 12:53 PM
hsai_BlockB3.Init.DataSize = SAI_DATASIZE_8;
hsai_BlockB3.SlotInit.SlotNumber = 32;
The hardware supports a maximum of 16 slots. Obviously for 8 channels one has to set... 8 slots! And, if you want the whole 8+24 bits of data, then set the data size to 32 bits.
> different terminology and that is wyh I do not understand how to set up SAI in STM32
> there is no much information about my questions, still looking and putting the pieces together
> That is why I am asking here - for understanding SAI
The reference manual for the MCU has all of the information about all peripherals.
2022-10-19 10:32 PM
Finally solution - works for 8 channel on 1 lin (1 channel is from 32 bits)!
hsai_BlockB3.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockB3.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
hsai_BlockB3.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockB3.Init.MonoStereoMode = SAI_MONOMODE;
hsai_BlockB3.Init.MonoStereoMode = SAI_STEREOMODE;
hsai_BlockB3.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockB3.Init.TriState = SAI_OUTPUT_NOTRELEASED;
hsai_BlockB3.Init.PdmInit.Activation = DISABLE;
hsai_BlockB3.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
hsai_BlockB3.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
hsai_BlockB3.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
hsai_BlockB3.SlotInit.FirstBitOffset = 1;
hsai_BlockB3.SlotInit.FirstBitOffset = 0;
hsai_BlockB3.SlotInit.SlotSize = SAI_SLOTSIZE_32B;
hsai_BlockB3.SlotInit.SlotNumber = 8;
hsai_BlockB3.SlotInit.SlotActive = 8;
hsai_BlockB3.SlotInit.SlotActive = SAI_SLOTACTIVE_0|SAI_SLOTACTIVE_1|SAI_SLOTACTIVE_2|SAI_SLOTACTIVE_3
|SAI_SLOTACTIVE_4|SAI_SLOTACTIVE_5|SAI_SLOTACTIVE_6|SAI_SLOTACTIVE_7;
2022-10-20 05:24 PM
hsai_BlockB3.Init.MonoStereoMode = SAI_MONOMODE;
hsai_BlockB3.Init.MonoStereoMode = SAI_STEREOMODE;
hsai_BlockB3.SlotInit.FirstBitOffset = 1;
hsai_BlockB3.SlotInit.FirstBitOffset = 0;
hsai_BlockB3.SlotInit.SlotActive = 8;
hsai_BlockB3.SlotInit.SlotActive = SAI_SLOTACTIVE_0|SAI_SLOTACTIVE_1|SAI_SLOTACTIVE_2|SAI_SLOTACTIVE_3|SAI_SLOTACTIVE_4|SAI_SLOTACTIVE_5|SAI_SLOTACTIVE_6|SAI_SLOTACTIVE_7;
I would not call it a good example. And the .SlotActive = 8 is just plain wrong. Also assigning SAI_SLOTACTIVE_ALL should also be OK.