‎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-05 11:26 PM
You can play cubeMX and changing the SAI parameters. Then see how the parameters you've mentioned will change. Also active frame length and slot and other specifications are explained in reference manual of IC. Frame synchronization active level length.
Also you can going in the MX code initializer and see how these fills registers and looking at reference manual to read their description.
‎2022-10-05 11:34 PM
I know this. I tried to.. but for example in datasheet of AD7771 is not any word about slots - they have maybe different terminology and that is wyh I do not understand how to set up SAI in STM32
for now I have this . I can read some data from ADC7771, but they looks weird:
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_32;
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_MONOMODE;
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 = 8;
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_DATASIZE;
hsai_BlockB3.SlotInit.SlotNumber = 1;
hsai_BlockB3.SlotInit.SlotActive = 1;
‎2022-10-05 11:39 PM
I think if you understand SAI protocols terminology then you must (maybe) understand your AD7771 and match them to be compatible.
‎2022-10-05 11:41 PM
That is why I am asking here - for understanding SAI
‎2022-10-07 02:44 AM
You're welcome, I've tried to learn you fishing instead of giving you the fish. Since most of the time people don't have time to dive into the deep of the detailed problem. I meant you could do this until someone give you exact answer. (Meanwhile you may find your answer and post it for others to benefiting them.)
‎2022-10-07 03:26 AM
ehm..
there is no much information about my questions, still looking and putting the pieces together...
‎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;