ESP32 i2s question

cyroan
Posts: 1
Joined: Mon Jun 14, 2021 8:32 am

ESP32 i2s question

Postby cyroan » Tue Jun 15, 2021 2:20 am

HI
I do a test connetting 16bit 2ch I2S ADC BOARD. I ground the signal and analyze it with logic analyzer. It show the value near +/-5count.
I got a strange signal when I write a arduino code to test. If I left all pin bit (LRCK/DATA/BITCK), no error reported from i2s_read() fucntion. The value in the buffer is all 0. I thought it should be a error returned.
Here is my test code
[Codebox]#include <driver/i2s.h>

#define I2S_SAMPLE_RATE 96000
//#define OUTPUT_PIN 27

#define READ_DELAY 9000 //microseconds

uint16_t adc_reading;

void i2sInit()
{
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = I2S_SAMPLE_RATE, // The format of the signal using ADC_BUILT_IN
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // is fixed at 12bit, stereo, MSB
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
//.communication_format = I2S_COMM_FORMAT_I2S_LSB,
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 2,
.dma_buf_len = 256,

.use_apll = false,//change to true @20210613
.tx_desc_auto_clear = false,
.fixed_mclk = 0//
};
static const i2s_pin_config_t pin_config = {
.bck_io_num = 26,// BCKL
.ws_io_num = 25,// LRCL
.data_out_num = -1,
.data_in_num = 33 /* DOUT*/
};
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &pin_config);

}

void reader(void *pvParameters) {
uint32_t read_counter = 0;
int16_t buffer[128] = {0};
size_t bytes_read;
i2sInit();
while (1) {

if (i2s_read(I2S_NUM_0, &buffer, sizeof(buffer), &bytes_read, portMAX_DELAY) == ESP_OK) {
//esp_err_ti2s_read(i2s_port_ti2s_num, void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait)
i2s_stop(I2S_NUM_0);
if (bytes_read == sizeof(buffer)) {
read_counter++;
for (int x = 0; x <= (sizeof(buffer) / 4)-1; x++) {
// Serial.printf("u16 %02x %02X\n",buffer[2*x],buffer[2*x+1]);
// Serial.printf("i16 %02x %02X\n",int16_t(buffer[2*x]),int16_t(buffer[2*x+1]));
//Serial.printf("%04x\n",buffer[2*x]);
Serial.printf("%d %d\n", buffer[2 * x],buffer[2 * x+1]);
}
//delay(100);
} else {
Serial.println("buffer empty");
}

i2s_start(I2S_NUM_0);
} else {
Serial.println("timeout");
}
}
}

void setup() {
Serial.begin(115200);
// Put a signal out on pin
//uint32_t freq = ledcSetup(0, I2S_SAMPLE_RATE, 10);
// Serial.printf("Output frequency: %d\n", freq);

//ledcAttachPin(OUTPUT_PIN, 0);
// Initialize the I2S peripheral

// Create a task that will read the data
xTaskCreatePinnedToCore(reader, "ADC_reader", 2048, NULL, 1, NULL, 1);
}

void loop() {

}[/Codebox]

Who is online

Users browsing this forum: joglz8 and 52 guests