ADC+I2S(DMA) conficts with "dac_output_enable": ADC reads 0x00 Values

ESPI_1
Posts: 10
Joined: Thu Feb 27, 2020 7:08 am

ADC+I2S(DMA) conficts with "dac_output_enable": ADC reads 0x00 Values

Postby ESPI_1 » Fri Mar 13, 2020 8:19 am

Using ADC+I2S alone works:
- Test: Simply Connect the ADC-Input to 3V3, and we got 0X0FFF in the Buffer as expected --> OK

BUG:
Simply adding the Line
"dac_output_enable(DAC_CHANNEL_1)"
somewere! in the Project - even after the test1,
then the test reads only 0X0000 from the ADC-via spi

seems to be a conflict in the Startup of the library
or some missing initialisation?

  1.  
  2. #include <stdint.h>
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "esp_log.h"
  6.  
  7. // DAC-Cosinus
  8. #include "soc/rtc_io_reg.h" //Used by DAC-Sin
  9. #include "soc/rtc_cntl_reg.h"
  10. #include "soc/rtc.h"
  11.  
  12. #include "driver/i2s.h"
  13. #include "driver/adc.h"
  14. #include "driver/dac.h"
  15. #include "esp_adc_cal.h"
  16. #include <soc/syscon_reg.h>
  17.  
  18. #define TAG "MyTag"
  19. #define EXAMPLE_I2S_ADC_CHANNEL     ADC1_CHANNEL_0 /*!< ADC1 channel 0 is GPIO36 (ESP32), GPIO1 (ESP32-S2) */
  20. //Externaly  Connect GPIO36 to 3v3
  21.  
  22. void MyTask(void* arg)
  23. {
  24.     i2s_config_t i2s_config = {
  25. //                  .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN | I2S_MODE_ADC_BUILT_IN,
  26.                 .mode = I2S_MODE_MASTER | I2S_MODE_RX                                       | I2S_MODE_ADC_BUILT_IN,
  27.        .sample_rate =  16000,
  28.        .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
  29.        .communication_format = I2S_COMM_FORMAT_I2S,
  30.        .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
  31.        .intr_alloc_flags = 1,
  32.        .dma_buf_count = 2,
  33.        .dma_buf_len = 1024,
  34.        .use_apll = 0,
  35.     };
  36.     adc1_config_channel_atten(EXAMPLE_I2S_ADC_CHANNEL, ADC_ATTEN_11db);
  37.     adc1_config_width(ADC_WIDTH_BIT_12);
  38.     i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
  39.     i2s_set_adc_mode(ADC_UNIT_1, EXAMPLE_I2S_ADC_CHANNEL);
  40.     i2s_adc_enable(I2S_NUM_0);
  41.  
  42.     const static size_t i2s_read_len = 1024;
  43.     size_t    bytes_read;
  44.     char*    i2s_read_buff    = (char*) calloc(i2s_read_len, sizeof(char));
  45.  
  46.     ESP_LOGI(TAG, "Test1: expect dump of 0X0FFF");
  47.     i2s_read(EXAMPLE_I2S_NUM, (void*) i2s_read_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
  48.     if(bytes_read>0){
  49.        ESP_LOG_BUFFER_HEXDUMP(TAG, i2s_read_buff, bytes_read, ESP_LOG_INFO );
  50.     }
  51.     vTaskDelay(2/portTICK_PERIOD_MS);
  52.  
  53.  
  54.     dac_cosine_enable(DAC_CHANNEL_1);
  55.    //********************* BUG BUG BUG BUG BUG ******************************************
  56.    // Simply enabeling "dac_output_enable" in Project --> BOTH!!!  Test1 and Test2 will Fail( read only 0X0000)
  57. #if 1
  58.     ESP_LOGI(TAG, "dac_output_enable");
  59.     dac_output_enable(DAC_CHANNEL_1);// GPIO25
  60. #endif
  61.  
  62.  
  63.     ESP_LOGI(TAG, "\nTest2:");
  64.     i2s_read(EXAMPLE_I2S_NUM, (void*) i2s_read_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
  65.     if(bytes_read>0){
  66.        ESP_LOG_BUFFER_HEXDUMP(TAG, i2s_read_buff, bytes_read, ESP_LOG_INFO );
  67.     }
  68.  
  69.     while(1){
  70.         vTaskDelay(2000/portTICK_PERIOD_MS);
  71.     }//while
  72. }
  73.  
  74.  
  75. void  ADC_SPI_DAC_Init(){
  76.      xTaskCreate(MyTask, "MyTask", 1024*3, NULL, 10, NULL);
  77. }
  78.  

Who is online

Users browsing this forum: No registered users and 2 guests