i2s Read Gives Data Even When Grounded

UnknownBotIndustries
Posts: 6
Joined: Mon Apr 01, 2024 3:22 am

i2s Read Gives Data Even When Grounded

Postby UnknownBotIndustries » Mon Apr 08, 2024 1:18 am

Hey all,
I'm back! The last time I posted here I had some problems with my audio codec AK5720VT, and the chip I was working with ESP32-C6 was crashing whenever I tried to use it. This was because of the size of the samples I was trying to allocate. Now I come with a different problem, in which I now receive massive amounts of data from the codec but nothing is being inputted into the codec. Even when the input for the codec is grounded, and even when I use a frequency generator to emulate audio.
Example Samples:
0
0
1107400585
25
1107400440
9
-1515870811
-1515870811
-1515870811
-1515870811
-1515870811
-1515870811
-1515870811
-1515870811
-1515870811
385876038
10354691
257536
-167771994
20840449
204288
503316646
4063235
99840
-1241513914
7733249
22016
1979711694
2490368
62976
1174405446
13434880
-12800
369098901
13959168
44544
1442840701
-2293760

Here's my code:
  1. #include <stdio.h>
  2. #include <driver\i2s_std.h>
  3. #include "driver\gpio.h"
  4. #include "freeRTOS\freeRTOS.h"
  5. #include "freeRTOS\task.h"
  6. void app_main(void)
  7. {
  8.     printf("Hello world!\n");
  9.     gpio_reset_pin(GPIO_NUM_5);
  10.     gpio_set_direction(GPIO_NUM_5, GPIO_MODE_OUTPUT);
  11.     gpio_set_level(GPIO_NUM_5, 1);
  12.     gpio_reset_pin(GPIO_NUM_6);
  13.     gpio_set_direction(GPIO_NUM_6, GPIO_MODE_OUTPUT);
  14.     gpio_set_level(GPIO_NUM_6, 0);
  15.     i2s_chan_handle_t rx_handle;
  16.     i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
  17.     i2s_new_channel(&chan_cfg, NULL, &rx_handle);
  18.  
  19.     i2s_std_config_t std_cfg = {
  20.         .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(8000),
  21.         .slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_24BIT, I2S_SLOT_MODE_STEREO),
  22.         .gpio_cfg = {
  23.             .mclk = GPIO_NUM_19,
  24.             .bclk = GPIO_NUM_18,
  25.             .ws = GPIO_NUM_20,
  26.             .dout = GPIO_NUM_NC,
  27.             .din = GPIO_NUM_21,
  28.             .invert_flags = {
  29.                 .mclk_inv = false,
  30.                 .bclk_inv = false,
  31.                 .ws_inv = false,
  32.             },
  33.         },
  34.     };
  35.     std_cfg.clk_cfg.mclk_multiple = I2S_MCLK_MULTIPLE_384;
  36.     i2s_channel_init_std_mode(rx_handle, &std_cfg);
  37.  
  38.     i2s_channel_enable(rx_handle);
  39.     int32_t raw_samples[300];
  40.     while (1) {
  41.         size_t bytes_read = 0;
  42.         i2s_channel_read(rx_handle, raw_samples, 3 * 100, &bytes_read, 20);
  43.         int samples_read = bytes_read / 3;
  44.         // dump the samples out to the serial channel.
  45.         for (int i = 0; i < samples_read; i++)
  46.         {
  47.             printf("%ld\n", raw_samples[i]);
  48.         }
  49.     }
  50. }
My schematics:
Screenshot 2024-03-31 205113.png
Screenshot 2024-03-31 205113.png (12.92 KiB) Viewed 2116 times
Screenshot 2024-03-31 205101.png
Screenshot 2024-03-31 205101.png (27.15 KiB) Viewed 2116 times
I really appreciate any information people can give me!

UnknownBotIndustries
Posts: 6
Joined: Mon Apr 01, 2024 3:22 am

Re: i2s Read Gives Data Even When Grounded

Postby UnknownBotIndustries » Tue Apr 09, 2024 3:33 am

Bump. Does anyone have any ideas? Do you guys need anything more information to answer? I'm truly out of ideas.

MicroController
Posts: 1701
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: i2s Read Gives Data Even When Grounded

Postby MicroController » Tue Apr 09, 2024 2:17 pm

Honestly, I'm not quite sure what you're question is actually about.
It sounds like you're asking about why you are receiving I2S samples from the ADC irrespective of its analog input signal. That one would be easily answered: The ADC will send a sample to the µC every time the µC requests one, i.e. for every 24 bit clocks the µC sends it will receive one sample from the ADC.

Or is your question about wrong/implausible sample values?
This may well have to do with the encoding/interpretation of the sample values. Specifically, values like -1515870811 are outside the possible range of a (singed) 24-bit value (i.e. +/- 2^23, or about +/- 8'000'000), so there's definitely some inconsistency there.

Edit: Looking at the chip's datasheet I found that it outputs its 24 bits 'left-aligned", so in fact it could also be the lowest 8 bits of a 32-bit value which are 0.
However, -1515870811 is 0xA5A5A5A5 which doesn't look too much like an actual ADC sample, and still is more than 24 bits.
(In the datasheet, 32-bit slots are used for the 24-bit data, so you may want to set up your I2S with I2S_SLOT_BIT_WIDTH_32BIT.)

Who is online

Users browsing this forum: Google [Bot] and 145 guests