大家好:
目前我使用ESP32 WROVER IDF 参考官方例程i2s_adc_dac读取电压时,打印数据都是0。代码如下:
void init_i2s()
{
i2s_config_t i2s_config;
i2s_config.mode = I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN;
i2s_config.sample_rate = I2S_SAMPLE_RATE;
i2s_config.dma_buf_len = I2S_BUFFER;
i2s_config.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT;
//i2s_config.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT;
i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
i2s_config.use_apll = false;
i2s_config.communication_format = I2S_COMM_FORMAT_PCM;
i2s_config.intr_alloc_flags = 0;
i2s_config.dma_buf_count = 5;
// install and start i2s driver
ESP_ERROR_CHECK( adc_gpio_init(ADC_UNIT_1, ADC_CHANNEL_0) );
ESP_ERROR_CHECK( i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL) );
ESP_ERROR_CHECK( i2s_set_adc_mode(ADC_UNIT_1, ADC1_CHANNEL_0) );
ESP_ERROR_CHECK( i2s_adc_enable(I2S_NUM_0) );
}
void sample_i2s()
{
ESP_LOGI(TAG, "Task called.");
//uint16_t i2s_buff[I2S_BUFFER];
int i2s_read_len = I2S_BUFFER;
char* i2s_buff = (char*) calloc(i2s_read_len, sizeof(char));
size_t bytes_read = 0;
//ESP_ERROR_CHECK( i2s_read(I2S_NUM_0, (void*) i2s_buff, i2s_read_len, &bytes_read, portMAX_DELAY) );
int error=i2s_read(I2S_NUM_0, (void*) i2s_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
printf("error=%d \r\n",error); //error=0
for(int i=0;i<i2s_read_len;i++)
{
printf("%2x ",i2s_buff); //读取的数据都是0
}
while(1);
}
打印信息如下:
[0;32mI (308) I2S: DMA Malloc info, datalen=blocksize=2048, dma_buf_count=5[0m
[0;32mI (318) I2S: PLL_D2: Req RATE: 44100, real rate: 2777.000, BITS: 16, CLKM: 30, BCK: 60, M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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
单次ADC采样的时候能读取正确的电压值,代码如下:
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_11db);
esp_adc_cal_characteristics_t characteristics;
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, V_REF, &characteristics);
while(1) {
uint32_t voltage;
esp_adc_cal_get_voltage(ADC1_TEST_CHANNEL, &characteristics, &voltage);
ESP_LOGI(TAG, "%d mV", voltage);
vTaskDelay(200 / portTICK_RATE_MS);
}
请问:如何配置I2S_ADC 才能正确的读取到电压值呢?
ESP32 WROVER IDF 使用i2s_adc读取电压时,打印数据都是0
Who is online
Users browsing this forum: No registered users and 49 guests