cancel
Showing results for 
Search instead for 
Did you mean: 

Troubleshooting STM32F746G-DISCOVERY I2S Communication with MAX98357 Amplifier - Error Code 1

CNEK1
Associate

Hello STM32 Community,

I am currently working on a project where I’m trying to test I2S communication with a MAX98357 amplifier using the STM32F746G-DISCOVERY board. I believe I have configured everything correctly, but I keep receiving an error code of 1 (HAL_ERROR) from the HAL_I2S_Transmit function, which prevents me from transmitting any data.

Here is the relevant part of my code:

#define SAMPLE_RATE 10000 
#define FREQ 140.0
#define PI 3.14159265
#define DEBUG_PRINTF(fmt, ...) \ UART_Printf("DEBUG: %s:%d: " fmt, __FILE__, __LINE__, __VA_ARGS__)

void generateSineWave(uint16_t *buffer, uint32_t size) {
for(uint32_t i = 0; i < size; i++) {
buffer[i] = (uint16_t)(0xFFF * (sin(2 * PI * FREQ * ((float)i / SAMPLE_RATE)) + 1.0) / 2.0);
}
}
uint16_t testToneBuffer[SAMPLE_RATE];
HAL_StatusTypeDef res;
void Play_Audio(uint16_t* pBuffer, uint32_t Size) {
  res = HAL_I2S_Transmit(&hi2s2, pBuffer, Size, 5000);
  if(res != HAL_OK) {
    DEBUG_PRINTF("I2S - ERROR, res = %d!\r\n", res);
    Error_Handler();
  }
  if(res == HAL_OK) {
    DEBUG_PRINTF("I2S - GOOD, res = %d!\r\n", res);
  }
}

And here is my clock configuration along with the I2S initialization:

void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 13;
RCC_OscInitStruct.PLL.PLLN = 216;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } i
f (HAL_PWREx_EnableOverDrive() != HAL_OK) { Error_Handler(); }
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7) != HAL_OK) { Error_Handler(); } }
static void MX_I2S2_Init(void) { hi2s2.Instance = SPI2; hi2s2.Init.Mode = I2S_MODE_MASTER_TX; hi2s2.Init.Standard = I2S_STANDARD_PHILIPS; hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B_EXTENDED; hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE; hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_32K; hi2s2.Init.CPOL = I2S_CPOL_LOW; hi2s2.Init.ClockSource = I2S_CLOCK_PLL; if (HAL_I2S_Init(&hi2s2) != HAL_OK) { Error_Handler(); } }

Despite the configurations, the HAL_I2S_Transmit does not seem to work, and no data is being transmitted. I’m not sure what I’m missing or if there’s an issue with my setup. Any insights or suggestions would be greatly appreciated.

Thank you in advance for your help!

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0 REPLIES 0