cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 PCM1808 endianness

TMich.1
Associate III

I am trying to get the PCM1808 ADC working on my STM32H7 using Cube IDE, but get stuck regarding endianness.
I understood STM32 is little endian and i2s is big endian. I am trying to receive 24 bit data via DMA but when reading my DMA buffer I am not sure of the endianness. The buffer is 16 bit so the 24 bit data is split into two and some zero's get added if I am understanding it correctly. My first byte is some number, the second is all zero's e.g.

1011110000000000

Then the third is always all 1's or all 0's and the last byte is some number again e.g.

1111111111111010 or 100

But I was expecting either the first three bytes to be a number or the last three and the rest to be 0's.

Does it automatically change the endianness from big to little per index in the buffer (16bits) or does it do it for the whole 32 bits. Or does the STM32 not do anything with the big endian number and just literally copy it into the DMA in big endian representation.

Is there something I'm missing?

DMA is set to circular word and SAI i2s is set to 32bit data.

 

1 REPLY 1
Saket_Om
ST Employee

Hello @TMich.1 

STM32 uses little-endian format. Concerning I2S, data are sent MSB first.

I assume that you have configured SAI to perform I2S transfer and set up a frame with 2 slots, each 32 bits per slot.

You also need to configure the data size, which is the number of data bits in each slot. I assume that you have set the data size to 32 bits, but the correct value should be 24 bits.

For instance, if you send 0xABCDEF (24 bits), because each slot is 32 bits, the last 8 bits sent will be 0. If you configure SAI with a data size of 32 bits, it will include the last 8 bits, resulting in the received value being 0xABCDEF00 (which is likely causing your issue).

However, if you configure SAI with a data size of 24 bits, it will only consider the first 24 bits, resulting in the correct received value of 0x00ABCDEF.

Could you please check and correct your configuration of the data size?

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar