cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H723 I2S or SAI

carloV
Associate II

Hi,

I need to use the I2S (or SAI) interface to connect a codec stereo working at 48KHz, 32bit word length and I2S connection; when I configure the multimedia I can select the SAI interface (SAI1 or SAI4) or one of the I2S interface available.

Which are the differences between them ? (I can configure the SAI as a I2S...)

Another question is:

I would like to use the DMA for the data transfers, for example using the I2S and the following HAL function:

 

HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_DMA(I2S_HandleTypeDef *hi2s, const uint16_t *pTxData, uint16_t *pRxData,

uint16_t Size)

 

What I need to understand is: - in what way the function works, for example in what way the stereo data are saved in the data buffer (Tx and Rx)- what happens when the codec send and receive data of 32bit length

 

Thank you, Luigi

 

 

2 REPLIES 2
ghrairim
ST Employee

Hello @carloV ,

The I2S interface is typically a subset of the SPI and is designed specifically for audio data. It supports standard audio formats and is easier to configure for simple stereo audio applications. But the SAI block is a dedicated audio block that is more versatile than I2S, and it supports multiple audio data formats and sampling rates, and it can be configured to work in different modes, such as master or slave, and can support more complex audio systems with multiple audio channels. Given that the SAI can be configured to work as an I2S interface, it offers greater flexibility if you need advanced features in the future.

For your second question: 

For 32-bit audio samples, your buffer should be an array of 32-bit words if you are directly transferring 32-bit samples. And if the function uses uint16_t for the buffer, as the prototype suggests, you might need to handle the data in 16-bit chunks even though the actual sample size is 32-bit. This could mean that each 32-bit sample is split into two 16-bit parts. And the DMA should be set up to match the data size and format expected by the I2S or SAI peripheral. You need to ensure that the DMA is configured for the correct memory data width and that the peripheral data width matches the codec's requirements. Then if the codec sends and receives 32-bit data, you have to ensure that the I2S or SAI peripheral is configured for 32-bit audio frames.

LCE
Principal

I like the SAI more, especially when it comes to synchronizing, it is much simpler with internal signals than I2S.

For example, take SAI 1 A as async master, which then controls the I2S clock outputs MCLK, SCLK, LRCK,

then select SAI 1 B as slave to 1 A. That way 1 B will only need the serial data input or output.

Which of the 2 you choose for TX / RX depends on your application.

Important for sync:
start DMA of slave first, then master

The slave SAI block won't do anything until it gets the clocks from the master SAI block.

 

Samples are sorted like in a wav file, so it's in old stereo audio style Left / Right:

LRLRLRLR...