Advertisement
Guest User

I2S config

a guest
Sep 18th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #define I2S_NUM         (0)
  2.  
  3. void configure_i2s() {
  4.   //i2s_adc_disable(I2S_NUM_0);
  5.   i2s_config_t i2s_config = {
  6.     .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),  // I2S receive mode with ADC
  7.     .sample_rate = samplingFrequency,                       // sample rate
  8.     .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,           // 16 bit I2S
  9.     .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,            // only the right channel
  10.     //.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
  11.     .communication_format = I2S_COMM_FORMAT_I2S_MSB,        // I2S format
  12.     .intr_alloc_flags = 0,                                  // none
  13.     .dma_buf_count = 16, //8                                 // number of DMA buffers
  14.     .dma_buf_len = NUM_SAMPLES,                             // number of samples
  15.     .use_apll = 0,                                          // no Audio PLL
  16.   };
  17.  
  18.    // ADC channel 0 with 11db (divide by input 3.6)
  19.   adc1_config_channel_atten(ADC_CHANNEL, ADC_ATTEN_11db);
  20.   // 12 bit ADC
  21.   adc1_config_width(ADC_WIDTH_12Bit);
  22.   // install I2S 0 driver, using event queue
  23.   i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
  24.   // ADC should use ADC_CHANNEL
  25.   i2s_set_adc_mode(ADC_UNIT_1, ADC_CHANNEL);
  26.   //vTaskDelay(5000/portTICK_RATE_MS);
  27.   // The raw ADC data is written in DMA in inverted form. This add aninversion:
  28.   SET_PERI_REG_MASK(SYSCON_SARADC_CTRL2_REG, SYSCON_SARADC_SAR1_INV);
  29.  
  30.   // enable I2S ADC
  31.   i2s_adc_enable(I2S_NUM_0);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement