- 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?
- #include <stdint.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_log.h"
- // DAC-Cosinus
- #include "soc/rtc_io_reg.h" //Used by DAC-Sin
- #include "soc/rtc_cntl_reg.h"
- #include "soc/rtc.h"
- #include "driver/i2s.h"
- #include "driver/adc.h"
- #include "driver/dac.h"
- #include "esp_adc_cal.h"
- #include <soc/syscon_reg.h>
- #define TAG "MyTag"
- #define EXAMPLE_I2S_ADC_CHANNEL ADC1_CHANNEL_0 /*!< ADC1 channel 0 is GPIO36 (ESP32), GPIO1 (ESP32-S2) */
- //Externaly Connect GPIO36 to 3v3
- void MyTask(void* arg)
- {
- i2s_config_t i2s_config = {
- // .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN | I2S_MODE_ADC_BUILT_IN,
- .mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN,
- .sample_rate = 16000,
- .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
- .communication_format = I2S_COMM_FORMAT_I2S,
- .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
- .intr_alloc_flags = 1,
- .dma_buf_count = 2,
- .dma_buf_len = 1024,
- .use_apll = 0,
- };
- adc1_config_channel_atten(EXAMPLE_I2S_ADC_CHANNEL, ADC_ATTEN_11db);
- adc1_config_width(ADC_WIDTH_BIT_12);
- i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
- i2s_set_adc_mode(ADC_UNIT_1, EXAMPLE_I2S_ADC_CHANNEL);
- i2s_adc_enable(I2S_NUM_0);
- const static size_t i2s_read_len = 1024;
- size_t bytes_read;
- char* i2s_read_buff = (char*) calloc(i2s_read_len, sizeof(char));
- ESP_LOGI(TAG, "Test1: expect dump of 0X0FFF");
- i2s_read(EXAMPLE_I2S_NUM, (void*) i2s_read_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
- if(bytes_read>0){
- ESP_LOG_BUFFER_HEXDUMP(TAG, i2s_read_buff, bytes_read, ESP_LOG_INFO );
- }
- vTaskDelay(2/portTICK_PERIOD_MS);
- dac_cosine_enable(DAC_CHANNEL_1);
- //********************* BUG BUG BUG BUG BUG ******************************************
- // Simply enabeling "dac_output_enable" in Project --> BOTH!!! Test1 and Test2 will Fail( read only 0X0000)
- #if 1
- ESP_LOGI(TAG, "dac_output_enable");
- dac_output_enable(DAC_CHANNEL_1);// GPIO25
- #endif
- ESP_LOGI(TAG, "\nTest2:");
- i2s_read(EXAMPLE_I2S_NUM, (void*) i2s_read_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
- if(bytes_read>0){
- ESP_LOG_BUFFER_HEXDUMP(TAG, i2s_read_buff, bytes_read, ESP_LOG_INFO );
- }
- while(1){
- vTaskDelay(2000/portTICK_PERIOD_MS);
- }//while
- }
- void ADC_SPI_DAC_Init(){
- xTaskCreate(MyTask, "MyTask", 1024*3, NULL, 10, NULL);
- }