Esp-idf: [TW#16751] ADC1 does not work in Multiple-channel scanning by pattern table, when enable WiFi.

Created on 29 Nov 2017  路  18Comments  路  Source: espressif/esp-idf

As stated in the "ESP32 Technical Reference Manual", in the "27.3.5 DIG SAR ADC Controllers" can perform high-speed scanning by pattern table. This is true only for the ADC2, because similar functionality is already exists in bootloader_random_enable(), selected analog inputs in the template table can read the analog signal in DMA. But this is not what we need, when you turn on the WiFi, the scaning is broken because wifi driver use some ADC2 lines.

  • ADC1 does not work in single scanning mode by pattern table?

- Unfortunately this example: i2s_adc_dac does not work, gets audio to ADC1 and writing empty data, even the channel number in the DMA data structure does not appear.

edited: 11.12.2017

I success to start the ADC1 I2S/DMA scan in the master branch of esp-idf, but if several conditions are fulfilled:

  • firstly, you need to change the power mode on the ADC_FORCE_ENABLE in the function adc_power_on(). I suggest for the function adc_power_on() the power mode to pass as argument so that when it is called from i2s_param_config (), the controller should be powered on permanently.

  • secondly, turn off the I2S controller reset in the function i2s_stop()

// I2S [i2s_num] -> conf.tx_reset = 1;
// I2S [i2s_num] -> conf.tx_reset = 0;
// I2S [i2s_num] -> conf.rx_reset = 1;
// I2S [i2s_num] -> conf.rx_reset = 0;

but since this affects the solution of the "bugfix/i2s_bck_polariy" I just deleted the function i2s_stop() here:

--- i2s.orig.c  2017-12-11 15:32:56.000000000 +0200
+++ i2s.c       2017-12-11 15:33:24.526230939 +0200
@@ -1043,7 +1043,6 @@
             ESP_LOGE(I2S_TAG, "Register I2S Interrupt error");
             return err;
         }
-        i2s_stop(i2s_num);
         err = i2s_param_config(i2s_num, i2s_config);
         if (err != ESP_OK) {
             i2s_driver_uninstall(i2s_num);

because i2s_stop() is called later from the function i2s_set_clk(). Apparently the repeated discharge here is superfluous and hinders the work.

BUT THAT IS VERY IMPORTANT !!!
when WIFI is turned on when the esp_wifi_set_mode() function is started, the previously running scan of ADC1/I2S/DMA is stopped, data in DMA does not change anymore, although I2S interrupts still arrive.
I think that the WiFi driver knocks down the settings of the DIG SAR ADC1 controller, but this is beyond my visibility, so I ask the guys from the Espressif to help solve this problem!

All 18 comments

It seems that ADC1 is working in scanning mode, if you return back to the feature(I2S-ADC): add ADC mode for I2S but after the Merge branch 'feature/i2s_built_in_adc' into 'master' it ceased.

We checkout to the earlier commit of esp-idf: "2fceec4" and we now have a microphone really records the sound. Will this be fixed in the near future?
What should I do to record two microphones for the left and right stereo channels at the same time?

We already have a branch fix i2s-adc function under merge reviewing. Will fix this soon.

@costaud Thank you for the good news, we are looking forward to it.

Hi! , good job! The example i2s_adc_dac work! I need some time to check this with together with Wifi in the project that I suspended 2 months ago.

Hi, please see simple code is that I tested this issue, here is an example: main.c

  • ADC-I2S Scanning does not normal start (more badly) after the reset of ESP32. It is necessary to add a delay of 5 seconds before switching on the ADC for a reliable start, this is issue.

  • The raw ADC data is written in DMA in inverted form. I have to manualy add an inversion:
    SET_PERI_REG_MASK(SYSCON_SARADC_CTRL2_REG, SYSCON_SARADC_SAR1_INV);
    before starting the ADC, please correct this.

  • Please allow global access to the template table customization function adc_set_i2s_data_pattern(). In order to set several ADC lines for scanning, Now I have to manually fill this table before starting the ADC, for example 1 and 4 ADC line simultaneous:
    SET_PERI_REG_BITS(SYSCON_SARADC_CTRL_REG, SYSCON_SARADC_SAR1_PATT_LEN, 1, SYSCON_SARADC_SAR1_PATT_LEN_S); WRITE_PERI_REG(SYSCON_SARADC_SAR1_PATT_TAB1_REG, 0x0E4E0000);
    and it works for me, what prevents you from doing it?

  • After running WiFi on esp_wifi_set_mode(), the ADC-I2S scanning is stops. This is the biggest issue.

@costaud Please make feedback to my comment. We really have such issues, can you tell how to get around them? I also failed to start ADC->I2S together with the enabled WiFi.

Hi phonec, sorry that these days are the Chinese Spring Festival Days, so all our engineers are on holiday. They will back to work in the next couple days. Sorry for the inconvenience.

@phonec , I can't access to your main.c.
We will have a test on those issues.

Hi @costaud, the main.c already exists in public gist: https://gist.github.com/phonec/42d685580b4c5b93c8b38d5fa68e0e58
there must be public access without restrictionons

FWIW, gist.github.com is not accessible from China. I am attaching the file here for reference.
42d685580b4c5b93c8b38d5fa68e0e58-eb519e6929be7a5abe20df28effdbbdc8d7919ae.zip

@igrr thank you for the help, did not know this. Obviously this is the strange issue of GFW.

Got it. Testing now.

Hi, @phonec. I have a test with your code and the results as you said, but when I turn on wifi befor init i2s, it woks. we will try to find the cause of the problem. thanks for your feedback.

OK, this is already something, but there may be cases when you need to initialize the Wi-Fi after the adc-i2s. Need to enter a delay before i2s_adc_enable(), for good starting?

Hi, @phonec
After some testing we found that there are indeed some configurations in the wifi initialization which will lead to the problems you described. our engineers are solving this bug. If there are any updates, we will reply to you immediately.
thanks !!!

Hi, @phonec ,
We have the rtc library updated on master and this issue has been solved. thanks !!

Hi @koobest, works fine, thanks !!
adc_set_i2s_data_pattern() and adc_set_i2s_data_len() in rtc_module.c
now do not must have to be static, we can call them to expand the scan table.

Was this page helpful?
0 / 5 - 0 ratings