ESP32 INMP441麦克风驱动

源代码:

#include <stdio.h>

#include "driver/i2s.h"

#include "esp_log.h"

static const int i2s_num = 0; // i2s port number

int32_t data_recv[4*1024];

void read_adc(void)

{

    int *i2s_bytes_read;

    while(1)

    {

        int32_t sample = 0;

        i2s_read(i2s_num, (char *)&sample,4, &i2s_bytes_read,portMAX_DELAY); // no timeout

        if (i2s_bytes_read > 0) {

            printf("%d\r\n", sample);

        }

        vTaskDelay(1);

    }

}

void app_main(void)

{

    i2s_config_t i2s_config = {

        .mode = I2S_MODE_MASTER | I2S_MODE_RX,

        .sample_rate = 16000,

        .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,

        .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,

        .communication_format = (I2S_COMM_FORMAT_I2S| I2S_COMM_FORMAT_I2S_MSB),//I2S_COMM_FORMAT_STAND_I2S,

        .tx_desc_auto_clear = false,

        .dma_buf_count = 4,

        .dma_buf_len = 8

    };

    static const i2s_pin_config_t pin_config = {

        .bck_io_num = 4,  //接clk

        .ws_io_num = 5, // 接ws

        .data_out_num = I2S_PIN_NO_CHANGE,

        .data_in_num = 18 // da

    };

   

    i2s_driver_install(i2s_num, &i2s_config, 0, NULL);   //install and start i2s driver

    i2s_set_pin(i2s_num, &pin_config);

    xTaskCreate(read_adc, "read_adc", 8*1024, NULL, 5, NULL);

}

使用串口工具将麦克风采集的数据显示出来

 

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值