arduino编译出错-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 371|回复: 0

[未解决] arduino编译出错

[复制链接]
发表于 2022-1-8 19:10 | 显示全部楼层 |阅读模式
  1. /**
  2. * ESP32 I2S Noise Level Example.
  3. *
  4. * This example calculates a mean noise level.
  5. * This example is Public Domain.
  6. *
  7. * @author maspetsberger
  8. */

  9. #include <driver/i2s.h>

  10. const i2s_port_t I2S_PORT = I2S_NUM_0;
  11. const int BLOCK_SIZE = 1024;

  12. void setup() {
  13.   Serial.begin(115200);
  14.   Serial.println("Configuring I2S...");
  15.   esp_err_t err;

  16.   // The I2S config as per the example
  17.   const i2s_config_t i2s_config = {
  18.       .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX), // Receive, not transfer
  19.       .sample_rate = 16000,                         // 16KHz
  20.       .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, // could only get it to work with 32bits
  21.       .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // although the SEL config should be left, it seems to transmit on right
  22.       .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
  23.       .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,     // Interrupt level 1
  24.       .dma_buf_count = 8,                           // number of buffers
  25.       .dma_buf_len = BLOCK_SIZE                     // samples per buffer
  26.   };

  27.   // The pin config as per the setup
  28.   const i2s_pin_config_t pin_config = {
  29.       .bck_io_num = 10,   // BCKL
  30.       .ws_io_num = 18,    // LRCL
  31.       .data_out_num = -1, // not used (only for speakers)
  32.       .data_in_num = 19   // DOUT
  33.   };

  34.   // Configuring the I2S driver and pins.
  35.   // This function must be called before any I2S driver read/write operations.
  36.   err = i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
  37.   if (err != ESP_OK) {
  38.     Serial.printf("Failed installing driver: %d\n", err);
  39.     while (true);
  40.   }
  41.   err = i2s_set_pin(I2S_PORT, &pin_config);
  42.   if (err != ESP_OK) {
  43.     Serial.printf("Failed setting pin: %d\n", err);
  44.     while (true);
  45.   }
  46.   Serial.println("I2S driver installed.");
  47. }

  48. void loop() {

  49.   // Read multiple samples at once and calculate the sound pressure
  50.   int32_t samples[BLOCK_SIZE];
  51.   int num_bytes_read = i2s_read_bytes(I2S_PORT,
  52.                                       (char *)samples,
  53.                                       BLOCK_SIZE,     // the doc says bytes, but its elements.
  54.                                       portMAX_DELAY); // no timeout
  55.   
  56.   int samples_read = num_bytes_read / 8;
  57.   if (samples_read > 0) {

  58.     float mean = 0;
  59.     for (int i = 0; i < samples_read; ++i) {
  60.       mean += samples[i];
  61.     }
  62.     Serial.println(mean);
  63.   }
  64. }

  65. // actually we would need to call `i2s_driver_uninstall(I2S_PORT)` upon exit.
复制代码
报错:

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 17:38 , Processed in 0.077447 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表