Skip to content

analogRead() returns bogus values when i2s DAC running #4782

Closed as not planned
@Harvie

Description

@Harvie

Hello, i have issues with analogRead() when running DMA for I2S DAC. To be honest i don't understand why running external DAC messes up internal ADC. But it surely is problem:

static const i2s_port_t i2s_num = I2S_NUM_0; // i2s port number

  static const i2s_config_t i2s_config = {    
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX /*| I2S_MODE_DAC_BUILT_IN*/ ),                                                                                                                                                            
    .sample_rate = SAMPLE_RATE,                                                                                             
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,  // only the top 8 bits will actually be used by the internal DAC, but using 8 bits stra> 
    .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,  // always use stereo output. mono seems to be buggy, and the overhead is insignifcant o> 
    .communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB),  // this appears to be the correct setting> 
    .intr_alloc_flags = 0, // default interrupt priority                                                                                    
    .dma_buf_count = 4,    // 8*128 bytes of buffer corresponds to 256 samples (2 channels, see above, 2 bytes per sample per channel)      
    .dma_buf_len = BUF_LEN,    
    .use_apll = false         
  };   

i2s_driver_install(i2s_num, &i2s_config, 0, NULL);   //install and start i2s driver

//i2s_adc_disable(i2s_num);  //Tried this, did not helped.

//So far i've only tested this issue on following three pins:
analogRead(2); //always returns 4095 no matter what signal on pin
analogRead(4); //always returns 4095 no matter what signal on pin
analogRead(35); //returns correct value measured by ADC on pin 35

Is there any chance to get proper ADC readings on all analog pins without shutting down I2S entirely? (this would cause audio glitching, so it is not possible)

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions