Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PCM5102 pomoc....
#8
#include <driver/i2s.h>
#include <math.h>

#define I2S_SAMPLE_RATE 44100
#define I2S_BCK_IO 26
#define I2S_WS_IO 22
#define I2S_DO_IO 25
#define PI 3.14159265

#define SIN_FREQ 1000
#define AMPLITUDE 10000
#define NUM_SAMPLES 44 // 44100 / 1000 = 44.1 ~ 44

int16_t sineWave[NUM_SAMPLES * 2]; // stereo (L + R)

void setupSineWave() {
for (int i = 0; i < NUM_SAMPLES; i++) {
int16_t sample = (int16_t)(AMPLITUDE * sin(2 * PI * i / NUM_SAMPLES));
sineWave[2 * i] = sample; // Left
sineWave[2 * i + 1] = sample; // Right
}
}

void setupI2S() {
const i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = I2S_SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false,
.tx_desc_auto_clear = true
};

const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_BCK_IO,
.ws_io_num = I2S_WS_IO,
.data_out_num = I2S_DO_IO,
.data_in_num = I2S_PIN_NO_CHANGE
};

i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &pin_config);
i2s_zero_dma_buffer(I2S_NUM_0);
}

void setup() {
Serial.begin(115200);
setupSineWave();
setupI2S();
}

void loop() {
size_t bytes_written;
i2s_write(I2S_NUM_0, sineWave, sizeof(sineWave), &bytes_written, portMAX_DELAY);
}
Reply


Messages In This Thread
PCM5102 pomoc.... - by Dragan83 - 05-06-2025, 06:47 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-06-2025, 06:52 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-06-2025, 06:57 PM
RE: PCM5102 pomoc.... - by savan - 05-06-2025, 09:31 PM
RE: PCM5102 pomoc.... - by savan - 05-06-2025, 09:45 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-07-2025, 07:36 PM
RE: PCM5102 pomoc.... - by savan - 05-06-2025, 09:49 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-07-2025, 07:01 PM
RE: PCM5102 pomoc.... - by Dragan83 - 05-07-2025, 07:02 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)