Using the ADC and DAC in combination with the I2S DMA

svdryse
Posts: 1
Joined: Thu Apr 06, 2017 8:00 am

Using the ADC and DAC in combination with the I2S DMA

Postby svdryse » Wed Jun 14, 2017 9:43 am

Hi,
I have a question about using the DAC and ADC. What I am trying to do is shown in the attached image: I want to generate a waveform using the DAC, send this waveform through some external hardware and then read out the resulting waveform with the ADC

Image

Due to the way we want to use this resulting waveform it is important that the sample rate is constant. That is why I want to use the I2S DMA to copy the bytes from memory to the DAC and from the ADC to memory. I've already been able to use the DMA for copying bytes to the DAC, but so far no luck with the ADC. According to the documentation this should be possible, but I don't find how the ESP32 should be configured to allow this.

The code that I currently use can be found in https://github.com/stevenvdr/esp-adc-bug. This uses the I2S DMA to copy bytes to the DAC and uses a loop to read out the ADC.

Probably the configuration will need to be changed to something like:

Code: Select all

static const i2s_config_t i2s_config = {
     .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX | I2S_MODE_DAC_BUILT_IN,
     .sample_rate = 44100,
     .bits_per_sample = 8, /* must be 8 for built-in DAC */
     .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
     .communication_format = I2S_COMM_FORMAT_I2S_MSB ,
     .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // high interrupt priority
     .dma_buf_count = 2,
     .dma_buf_len = 128
};
And for connecting the ADC to the I2S interface I've tried the following with no luck.

Code: Select all

	
// Setup ADC
adc1_config_channel_atten(ADC1_CHANNEL_5, ADC_ATTEN_11db);
adc1_config_width(ADC_WIDTH_12Bit);
REG_SET_BIT(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_DATA_TO_I2S);
    
i2s_read_bytes(I2S_NUM, (char*) &samples, 256, portMAX_DELAY);
Probably what I am missing is some configuration that tells the ESP32 to connect the ADC to the I2S. This will probably be similar to https://github.com/espressif/esp-idf/bl ... r_random.c, where the ADC values are redirected to the RNG to create a random value. But there is no documentation on what to activate/enable to do this.

Kind regards,
Steven

Who is online

Users browsing this forum: No registered users and 129 guests