[solved] Internal ADC sampling via i2s and bluetooth problem

ale1973
Posts: 1
Joined: Mon Feb 17, 2020 6:58 pm

[solved] Internal ADC sampling via i2s and bluetooth problem

Postby ale1973 » Tue Feb 18, 2020 1:20 pm

Solution:
the problem was power save mode in wifi, solved adding
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));


Hello, i'm working with i2s_adc_dac example, and work fine, but, when add bluetooth, the adc value stay fix in a random value.
also, i was testing the example btt_spp_acceptor, this example work fine, then i add adc read via i2s interface, and same results
adc reading, stay fix in randon value, if i deactivate bluetooth, then adc via i2s, work fine, any idea?

i use Esp idf 3.3.1 december version
esp32 wrover devkit v1.1

this is the code for i2s adc reading

thanks in advance.

Alejandro.

PS: sorry for my english



Code: Select all

#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/i2s.h"
#include "driver/adc.h"
#include "driver/ledc.h"
#include "dig_i2s_adc.h"
#include "i2s_adc.h"


//I2S built-in ADC unit
#define I2S_ADC_UNIT              ADC_UNIT_1
//I2S built-in ADC channel
    #define I2S_ADC_CHANNEL           ADC1_CHANNEL_0


void example_disp_buf(uint8_t* buf, int length)
{
    printf("======\n");
    for (int i = 0; i < length; i++) {
        printf("%02x ", buf[i]);
        if ((i + 1) % 2 == 0) {
            printf("\n");
        }
    }
    printf("======\n");
}

void example_i2s_init(void)
{
    ESP_LOGI("I2S ADC","init i2s");
	 int i2s_num = 0;
	 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,
        .sample_rate =  44100,
        .bits_per_sample = 16,
	    .communication_format = I2S_COMM_FORMAT_I2S_MSB,
	    .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
	    .intr_alloc_flags = 0,
	    .dma_buf_count = 2,
	    .dma_buf_len = 1024,
	    .use_apll = 1,
	 };
	 //install and start i2s driver
	 i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
	 //init DAC pad
	 i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
	 //init ADC pad
	 i2s_set_adc_mode(I2S_ADC_UNIT, I2S_ADC_CHANNEL);
}

/**
 * @brief I2S ADC/DAC example
 *        1. Erase flash
 *        2. Record audio from ADC and save in flash
 *        3. Read flash and replay the sound via DAC
 *        4. Play an example audio file(file format: 8bit/8khz/single channel)
 *        5. Loop back to step 3
 */
void i2s_adc_task(void *arg)
{
    ESP_LOGI("I2S ADC","Iniciando adc task");
    int i2s_read_len = 16 * 1024;
    int flash_wr_size = 0;
    size_t bytes_read;
    char* i2s_read_buff = (char*) calloc(i2s_read_len, sizeof(char));
    example_i2s_init();
    i2s_adc_enable(I2S_NUM_0);
    while (1) {
        
        //read data from I2S bus, in this case, from ADC.
        i2s_read(I2S_NUM_0, (void*) i2s_read_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
        example_disp_buf((uint8_t*) i2s_read_buff, 512);
        //i2s_adc_disable(I2S_NUM_0);
        vTaskDelay(5000 / portTICK_PERIOD_MS);
    }
}

RinmoDo
Posts: 2
Joined: Tue Apr 06, 2021 12:11 pm

Re: [solved] Internal ADC sampling via i2s and bluetooth problem

Postby RinmoDo » Thu Apr 22, 2021 6:34 pm

I have the same issue, any solutions u tried beside the power save mode ..?

can u check my code here : https://github.com/RinmoDo/Sampling_w_BLE

Who is online

Users browsing this forum: Google [Bot] and 459 guests