目前我使用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.communica
tion_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