大家好:
目前我使用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
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: Baidu [Spider] and 86 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.