Projet

Général

Profil

document code micro 2

Documentation utilisateur
24/03/2023

#Inclure <driver/i2s.h>

// Vous ne devriez pas avoir besoin de modifier ces paramètres
#Définir SAMPLE_BUFFER_SIZE 512
#Définir SAMPLE_RATE 8000
// la plupart des microphones seront probablement par défaut sur le canal gauche, mais vous devrez peut-être attacher la broche L / R bas
#Définir I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
// câblez votre microphone aux mêmes broches ou changez-les pour qu’elles correspondent à votre câblage
#Définir I2S_MIC_SERIAL_CLOCK GPIO_NUM_32
#définir I2S_MIC_LEFT_RIGHT_CLOCK GPIO_NUM_25
#Définir I2S_MIC_SERIAL_DATA GPIO_NUM_33

// Ne plaisante pas avec ça
i2s_config_t i2s_config = {
. mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
. sample_rate = SAMPLE_RATE,
. bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
. channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
. communication_format = I2S_COMM_FORMAT_I2S,
. intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
. dma_buf_count = 4,
. dma_buf_len = 1024,
. use_apll = faux,
. tx_desc_auto_clear = faux,
. fixed_mclk = 0};

// et ne plaisante pas avec ça
i2s_pin_config_t i2s_mic_pins = {
. bck_io_num = I2S_MIC_SERIAL_CLOCK,
. ws_io_num = I2S_MIC_LEFT_RIGHT_CLOCK,
. data_out_num = I2S_PIN_NO_CHANGE,
. data_in_num = I2S_MIC_SERIAL_DATA};

Configuration de Void () {
// Nous avons besoin d’une sortie série pour le traceur
Feuilleton. Début(115200);
// démarrer le périphérique I2S
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &i2s_mic_pins);
}

int32_t raw_samples[SAMPLE_BUFFER_SIZE];
Boucle vide () {
// lecture à partir de l’appareil I2S
size_t bytes_read = 0;
i2s_read(I2S_NUM_0, raw_samples, taille(int32_t) * SAMPLE_BUFFER_SIZE, &bytes_read, portMAX_DELAY);
int samples_read = bytes_read / sizeof(int32_t);
// vider les échantillons sur le canal série.
for (int i = 0; i < samples_read; i++) {
Feuilleton. printf(« %ld\n », raw_samples[i]);
}
}

Fichiers