cancel
Showing results for 
Search instead for 
Did you mean: 

Setup SAI - read adc values from AD7771 via DOUTx interface lines

JR2963
Senior

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)0693W00000UFReDQAX.png 

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.

12 REPLIES 12
Piranha
Chief II
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.

JJRR
Senior

 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;

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.