ESP32 I2S audio to MAX98357A

robpelu
Posts: 4
Joined: Fri Dec 29, 2017 5:57 pm

ESP32 I2S audio to MAX98357A

Postby robpelu » Sun Jul 15, 2018 6:51 pm

Hello all, I'm reproducing some audio from the ESP32 to a MAX98357A via I2S.
It works ok the first time, but following calls to the play() function doesn't work.

I've tried to erase the DMA buffer, i2s_stop(), i2s_start(), not uninstalling the i2s driver, with no success.

The samples are stored in flash inside an array, that works ok.

Have this ever happened to you or do you have some idea to try ?

BR, Robert.

Code: Select all

#include "driver/i2s.h"

#define SAMPLE_RATE     (22055)
#define I2S_NUM         (0)

void sound_i2s()
{
	int counter=0;

    i2s_config_t i2s_config = {
        .mode = I2S_MODE_MASTER | I2S_MODE_TX,                                  // Only TX
        .sample_rate = SAMPLE_RATE,
        .bits_per_sample = 16,                                                  //16-bit per channel
        .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,                           //2-channels
        .communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB,
        .dma_buf_count = 6,
        .dma_buf_len = 1024,                                                      //
        .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1                                //Interrupt level 1
    };
    i2s_pin_config_t pin_config = {
        .bck_io_num = 26,
        .ws_io_num = 25,
        .data_out_num = 27,
        .data_in_num = -1                                                       //Not used
    };

    i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
    i2s_set_pin(I2S_NUM, &pin_config);
    
    while(counter < NUM_ELEMENTS)
    {
    	i2s_push_sample(I2S_NUM, (char *) &data[counter], portMAX_DELAY);
    	counter += 2;
    }

    i2s_driver_uninstall(I2S_NUM);
    
}

robpelu
Posts: 4
Joined: Fri Dec 29, 2017 5:57 pm

Re: ESP32 I2S audio to MAX98357A

Postby robpelu » Sun Jul 29, 2018 12:13 pm

Well, when I've posted this only worked the first time, then had to restart the ESP to make it work again.
When showing this to some other person worked like a charm every time without restarts, don't know why :roll:

BR, Robert.

Who is online

Users browsing this forum: Bing [Bot], dkovar and 135 guests