cancel
Showing results for 
Search instead for 
Did you mean: 

SPH0645_I2S_Error

vbk22398
Senior

I am using STM32F407VG in my project temporarily. The objective is to transmit audio data over ethernet which is received in this mic and received audio from the other end this side having stm32 as the MCU. 

STM32_I2S.png

 For Mic, I am using SPH0645. But I am unable to sample the audio correctly. I am facing the same issue as in the following link. 

https://community.st.com/t5/stm32-mcus-products/unexpected-behaviors-in-dma-buffer-for-i2s-mems-microphone/td-p/725679

my_code:


uint16_t data_in[100] = { 0 };
volatile int16_t sample_i2s;

void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) {
sample_i2s = data_in[0];
}

int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_I2S2_Init();
/* USER CODE BEGIN 2 */
HAL_I2S_Receive_DMA(&hi2s2,(uint16_t*)&data_in[0],100);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

i am unable to read the I2S audio buffer properly. 

Screenshot 2025-03-27 131119.png

Screenshot 2025-03-27 131200.png


The output when i plot the variable "sample_i2s" is

 

Screenshot 2025-03-27 131723.png


Note: 
STM32F407VG board is chosen just because it has I2S pins. For transferring via the Ethernet, I am going to use STM32F767ZI and I am using this Discovery board for time being. So if anyone have a solution, Kindly do reply in the same thread.

Thank You.







1 ACCEPTED SOLUTION

Accepted Solutions
vbk22398
Senior

Since I am using STM32F407VG Discovery board which has an on-board mic, the issue is resolved after removing this on-board mic and the results are proper when using the I2S bus that concern this on-board Mic. It is not the issue that concern SPH0645 Mic. Use the I2S Line that is connected with the on-board Mic after removing and interface with the I2S mic which is SPh0645.

View solution in original post

9 REPLIES 9
mbarg.1
Senior II
Sorry, i do not have this hw (SPH0645) - cannot help.
Ozone
Principal

Glancing over it, the output plot seems to suggest a data size issue somewhere.
Every other data item zero point to a systematic issue.

I don't have the hardware either, nor do I use Cube.

> i am unable to read the I2S audio buffer properly. 

I think you talk about the F4 discovery board here, which came with SPL examples that make use of the CS43L22 audio codec.
Perhaps you can compare the relevant code, especially initialisation.

@mbarg.1 Thank you for the reply!

Thank you for the reply.! 

 

AScha.3
Chief III

You set the DMA on word,32b, but from my experience the F4 i2s is not working correctly then. So try settings with half word, 16b, and also the data in int16 .

The i2S working correctly then.

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

@AScha.3 Will try and update you!

 


@AScha.3 wrote:

So try settings with half word, 16b, and also the data in int16 .

Same results!


 

vbk22398
Senior

Since I am using STM32F407VG Discovery board which has an on-board mic, the issue is resolved after removing this on-board mic and the results are proper when using the I2S bus that concern this on-board Mic. It is not the issue that concern SPH0645 Mic. Use the I2S Line that is connected with the on-board Mic after removing and interface with the I2S mic which is SPh0645.

gregstm
Senior III

Glad you have solved your problem. I've done a fair bit of experimenting with the SPH0645. If you have trouble with a large (and varying) DC offset in the data from the microphone, perhaps give the TDK T5848 I2S microphone a try - I've been very impressed with its performance and features - although the maximum supply voltage of 2V is a bit of a nuisance.