cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 I2S Callback and Data Width Clarification

lukegalea16
Associate II

Hi,

I am using the STM32F407VG and PmodI2S2 to transfer 24-bit audio. For the most part I have followed this tutorial. So far everything works and I have audio throughput and the ability to manipulate it.

In order to understand better the underlying code, I want to understand the following:
1. In I2S2 > Parameter Settings > Data and Frame Format I have setup 24 bits Data on 32 Bits Frame and in DMA Settings > I2S2_EXT_RX and SPI2_TX I have Data Width set to Half Word. Currently I am receiving 16-bit data which I then restructure into a 32-bit int variable. Would it be possible to receive 32-bit data directly by selecting a data width of Word? I'm a bit confused about this as the method to setup the DMA (HAL_I2SEx_TransmitReceive_DMA) only accepts pointers to a uint16_t even after selecting a data width of word.

2. If I2S2 > DMA Settings has two DMA requests (I2S2_EXT_RX and SPI2_TX), does this mean that the callbacks 'HAL_I2SEx_TxRxHalfCpltCallback' and 'HAL_I2SEx_TxRxCpltCallback' are called on both Tx and Rx interrupts? My concern here is that the incoming samples would then be processed twice.

Thanks

3 REPLIES 3
AScha.3
Chief II

Hi,

>1. read in rm :

AScha3_0-1719950894236.png

So you can set here 32b data, but the SPI has only 16b shifter, so it needs 2x load with 16b to send /receive a 32b word. (On "bigger" chips you could use SAI , can set data 8...32 bits. But here only 8...16.)

Maybe you could set the buffer as a union, 16b for dma and 32b for "data" .

>2. Try it...

Should be: on half/full TxRx---fCpltCallback you get this buffer to use, and have to set the next data in to send, before next callback coming. Then process read/write the other half of each buffer.

If you feel a post has answered your question, please click "Accept as Solution".
  1. I tried using 32b, but the audio is distorted then - I think that the format of the data is getting changed?
  2. I am reading/writing different parts of the buffer depending on whether it's a half or full callback. I'm just concerned that 'HAL_I2SEx_TxRxHalfCpltCallback' gets called twice (i.e. on Tx and Rx) instead of once for both? (not sure if this makes sense)

 

1. I just can say: with F411, also F4 series, on I2C , with 16b working fine; with 32b - i didnt get it work correct.

Maybe chip problem, because sometimes it working correct, most (!) time it puzzled data, sync was in middle of 32b - unusable. (I use H743 now...SAI working perfect .)

Here probably just wrong order (big/little endian problem), so try : reorder by software. (exchange lo/hi 16b part)

 

2. TxRx is at same time, so if calling TxRxHalfCpltCallback should be only one time, for both, rx tx.

Try...it will nothing explode.

If you feel a post has answered your question, please click "Accept as Solution".