8 years, 8 months ago.

Setting correct Parameters for I2s to receive 24bit

Hi I am new to microcontroller programming and this forum. I am trying to read a digital MEMS microphone via I2S with a nucleo stm32f411re. The microphone sends 24bits per frame. I am trying to use the HAL_I2S_Receive function but I am confused how to set the parameters and it would be great if somebody could help me.

I have tried:

char buffer[50];
uint16_t len;
HAL_StatusTypeDef ReadStatus;
uint16_t i2sValue;
uint16_t *I2S_RX_Buffer=&i2sValue;

ReadStatus= HAL_I2S_Receive(&hi2s1, I2S_RX_Buffer, 24, 0xFFFF);
while(ReadStatus!=0)
{ }
sprintf(buffer,"I2S value: %u \r\n",i2sValue);
len=strlen(buffer);
HAL_UART_Transmit(&huart2, buffer, len, 1000);

Relevant API Documentation

HAL_StatusTypeDef HAL_I2S_Receive (I2S_HandleTypeDef * hi2s, uint16_t * pData, uint16_t Size, uint32_t Timeout )

Parameters:
hi2s,: I2S handle
pData,: a 16-bit pointer to data buffer.
Size,: number of data sample to be sent:

Note:
When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S configuration phase, the Size parameter means the number of 16-bit data length in the transaction and when a 24-bit data frame or a 32-bit data frame is selected the Size parameter means the number of 16-bit data length.

My question

How do I need to set the parameters pData and Size to get it working. Shouldn't pData be a uint32_t because I need to store 24 bits? Also the note in the API Documentation is kind of confusing to me.

Be the first to answer this question.