完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好:
目前我使用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 rn",error); //error=0 for(int i=0;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, MCLK: 30.234,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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 单次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 才能正确的读取到电压值呢? |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
542浏览 6评论
454浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
434浏览 5评论
436浏览 4评论
409浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-19 08:51 , Processed in 0.833146 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号