Mellan DIR9001 (S/P-DIF-dekoder) och PCM1794 (DAC).
Denna kod enligt exempel från nätet,
Kod: Markera allt
// Include I2S driver
#include <driver/i2s.h>
// Connections to I2S
#define I2S_WS 25
#define I2S_SD 33
#define I2S_SCK 32
// Use I2S Processor 0
#define I2S_PORT I2S_NUM_0
// Define input buffer length
#define bufferLen 64
int32_t sBuffer[bufferLen];
void i2s_install() {
// Set up I2S Processor configuration
const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_SLAVE | I2S_MODE_RX),
.sample_rate = 48000, //44100,
.bits_per_sample = i2s_bits_per_sample_t(24),
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = bufferLen,
.use_apll = false
};
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
}
void i2s_setpin() {
// Set I2S pin configuration
const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};
i2s_set_pin(I2S_PORT, &pin_config);
}
void setup() {
// Set up Serial Monitor
Serial.begin(115200);
Serial.println(" ");
delay(1000);
// Set up I2S
i2s_install();
i2s_setpin();
i2s_start(I2S_PORT);
delay(500);
}
void loop() {
// Get I2S data and place in data buffer
static int counter = 0;
size_t bytesIn = 0;
esp_err_t result = i2s_read(I2S_PORT, &sBuffer, bufferLen, &bytesIn, portMAX_DELAY);
if (result == ESP_OK)
{
counter++;
if(counter == 1000) {
counter = 0;
for(int i = 0; i < bytesIn/4; i++) {
Serial.println(sBuffer[i]);
}
}
}
}
Kod: Markera allt
-1441792
16771840
-1376256
16772352
-1245184
16772864
-1114112
16773376
-983040
16771328
-1507328
16771328
-1507328
16771584
-1441792
16771584
-1441792
16772096
-1310720
16772352
-1245184
16772864
-1114112
16773376
-983040
16771328
-1507328
16771328
-1507328