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.SlotInit.SlotActive = 0x00000000;

You have not enabled any slot.

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:

  • hsai_BlockB3.SlotInit.SlotActive - What does it mean? I want to have 8 channels on DOUT_1 line - so there is 32 slots? Or all this "pack" is taken as 1 slot?
  • hsai_BlockB3.Init.DataSize - for me it should be 32? (1 channel sends 4 bytes)
  • hsai_BlockB3.FrameInit.FrameLength = 256; - it sounds good for me when I want to read 8 channels (1 channel have 1 B header and 3 B for ADC data) 4x8x8 = 256 bits
  • what bout that? hsai_BlockB3.FrameInit.ActiveFrameLengt
  • what bout that? hsai_BlockB3.SlotInit.SlotNumber

SeyyedMohammad
Senior III

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.

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;

I think if you understand SAI protocols terminology then you must (maybe) understand your AD7771 and match them to be compatible.

That is why I am asking here - for understanding SAI 😀

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.)

ehm..

there is no much information about my questions, still looking and putting the pieces together...

JR2963
Senior

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;