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:
- #include <stdio.h>
- #include <driver\i2s_std.h>
- #include "driver\gpio.h"
- #include "freeRTOS\freeRTOS.h"
- #include "freeRTOS\task.h"
- void app_main(void)
- {
- printf("Hello world!\n");
- gpio_reset_pin(GPIO_NUM_5);
- gpio_set_direction(GPIO_NUM_5, GPIO_MODE_OUTPUT);
- gpio_set_level(GPIO_NUM_5, 1);
- gpio_reset_pin(GPIO_NUM_6);
- gpio_set_direction(GPIO_NUM_6, GPIO_MODE_OUTPUT);
- gpio_set_level(GPIO_NUM_6, 0);
- i2s_chan_handle_t rx_handle;
- i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
- i2s_new_channel(&chan_cfg, NULL, &rx_handle);
- i2s_std_config_t std_cfg = {
- .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(8000),
- .slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_24BIT, I2S_SLOT_MODE_STEREO),
- .gpio_cfg = {
- .mclk = GPIO_NUM_19,
- .bclk = GPIO_NUM_18,
- .ws = GPIO_NUM_20,
- .dout = GPIO_NUM_NC,
- .din = GPIO_NUM_21,
- .invert_flags = {
- .mclk_inv = false,
- .bclk_inv = false,
- .ws_inv = false,
- },
- },
- };
- std_cfg.clk_cfg.mclk_multiple = I2S_MCLK_MULTIPLE_384;
- i2s_channel_init_std_mode(rx_handle, &std_cfg);
- i2s_channel_enable(rx_handle);
- int32_t raw_samples[300];
- while (1) {
- size_t bytes_read = 0;
- i2s_channel_read(rx_handle, raw_samples, 3 * 100, &bytes_read, 20);
- int samples_read = bytes_read / 3;
- // dump the samples out to the serial channel.
- for (int i = 0; i < samples_read; i++)
- {
- printf("%ld\n", raw_samples[i]);
- }
- }
- }