完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
在idf的例程中复制项目i2s_basic,我尝试修改采样率来提高i2s的频率,当我设置采样率到150000,使用逻辑分析仪测量bck_io的频率为9.7MHz,我接着往大的设置,尝试了250000,350000....625000。发现bck_io的频率最高只能到15MHZ,设置高了也没有效果。
/* I2S Example This example code will output 100Hz sine wave and triangle wave to 2-channel of I2S driver Every 5 seconds, it will change bits_per_sample [16, 24, 32] for i2s data This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.*/#include #include "freertos/FreeRTOS.h"#include "freertos/task.h"#include "driver/i2s.h"#include "driver/gpio.h"#include "esp_system.h"#include "esp_log.h"#include #define SAMPLE_RATE (150000)#define I2S_NUM (0)#define WAVE_FREQ_HZ (100)#define PI (3.14159265)#define I2S_BCK_IO (GPIO_NUM_4)#define I2S_WS_IO (GPIO_NUM_5)#define I2S_DO_IO (-1)#define I2S_DI_IO (GPIO_NUM_18)#define SAMPLE_PER_CYCLE (SAMPLE_RATE/WAVE_FREQ_HZ)static const char* TAG = "i2s_example";int16_t i2s_readraw_buff[400];static void setup_triangle_sine_waves(int bits){ int *samples_data = malloc(((bits+8)/16)*SAMPLE_PER_CYCLE*4); unsigned int i, sample_val; double sin_float, triangle_float, triangle_step = (double) pow(2, bits) / SAMPLE_PER_CYCLE; size_t i2s_bytes_write = 0; printf("rnTest bits=%d free mem=%d, written data=%dn", bits, esp_get_free_heap_size(), ((bits+8)/16)*SAMPLE_PER_CYCLE*4); triangle_float = -(pow(2, bits)/2 - 1); for(i = 0; i < SAMPLE_PER_CYCLE; i++) { sin_float = sin(i * 2 * PI / SAMPLE_PER_CYCLE); if(sin_float >= 0) triangle_float += triangle_step; else triangle_float -= triangle_step; sin_float *= (pow(2, bits)/2 - 1); if (bits == 16) { sample_val = 0; sample_val += (short)triangle_float; sample_val = sample_val << 16; sample_val += (short) sin_float; samples_data[i] = sample_val; } else if (bits == 24) { //1-bytes unused samples_data[i*2] = ((int) triangle_float) << 8; samples_data[i*2 + 1] = ((int) sin_float) << 8; } else { samples_data[i*2] = ((int) triangle_float); samples_data[i*2 + 1] = ((int) sin_float); } } ESP_LOGI(TAG, "set clock"); i2s_set_clk(I2S_NUM, SAMPLE_RATE, bits, 2); //Using push // for(i = 0; i < SAMPLE_PER_CYCLE; i++) { // if (bits == 16) // i2s_push_sample(0, &samples_data[i], 100); // else // i2s_push_sample(0, &samples_data[i*2], 100); // } // or write ESP_LOGI(TAG, "write data"); i2s_write(I2S_NUM, samples_data, ((bits+8)/16)*SAMPLE_PER_CYCLE*4, &i2s_bytes_write, 100); free(samples_data);}void app_main(void){ //for 36Khz sample rates, we create 100Hz sine wave, every cycle need 36000/100 = 360 samples (4-bytes or 8-bytes each sample) //depend on bits_per_sample //using 6 buffers, we need 60-samples per buffer //if 2-channels, 16-bit each channel, total buffer is 360*4 = 1440 bytes //if 2-channels, 24/32-bit each channel, total buffer is 360*8 = 2880 bytes i2s_config_t i2s_config = { .mode = I2S_MODE_MASTER | I2S_MODE_RX, .sample_rate = SAMPLE_RATE, .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, .channel_format = I2S_CHANNEL_FMT_ALL_LEFT, .communication_format = I2S_COMM_FORMAT_STAND_MSB, .dma_buf_count = 6, .dma_buf_len = 60, .use_apll = true, .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 //Interrupt level 1 }; 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_DI_IO //Not used }; i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL); i2s_set_pin(I2S_NUM, &pin_config); // i2s_set_clk(I2S_NUM, SAMPLE_RATE, I2S_BITS_PER_SAMPLE_16BIT, 2); size_t bytes_read; while (1) { // setup_triangle_sine_waves(test_bits); i2s_read(I2S_NUM, i2s_readraw_buff, 200, &bytes_read, portMAX_DELAY); printf("read i2s %d:",bytes_read); for(int i = 0;i < 200; i++) { printf("%x ",i2s_readraw_buff[i]); } printf("n"); vTaskDelay(5000/portTICK_RATE_MS); }} |
|
相关推荐
1个回答
|
|
|
要解决ESP32的I2S同步时钟BCK(位时钟)最高输出时钟达不到手册标称的40MHz的问题,可以尝试以下步骤:
1. **检查硬件连接**:确保I2S相关的硬件连接正确,包括数据线、时钟线等。错误的硬件连接可能导致信号不稳定或频率降低。 2. **检查电源稳定性**:I2S模块对电源稳定性有一定要求,不稳定的电源可能导致时钟频率无法达到预期。 3. **检查I2S配置**:在代码中检查I2S配置,确保配置正确。例如,确保I2S的时钟分频器设置正确,以便达到所需的频率。 4. **检查I2S驱动版本**:确保使用的ESP-IDF版本是最新的,因为新版本可能修复了一些已知的问题。 5. **调整时钟源**:ESP32的I2S模块可以配置使用不同的时钟源。尝试更改时钟源,看看是否能提高BCK的频率。 6. **使用外部时钟**:如果内部时钟无法满足需求,可以考虑使用外部时钟源来驱动I2S模块。 7. **分析I2S模块限制**:阅读ESP32的技术手册,了解I2S模块在不同配置下的频率限制。这有助于确定问题是否由硬件限制引起。 8. **优化代码**:检查代码中是否有可能导致I2S性能下降的部分,例如在I2S传输过程中的延时或阻塞操作。 9. **使用调试工具**:使用逻辑分析仪等工具来监测I2S信号,以便更好地了解问题所在。 |
|
|
|
|
只有小组成员才能发言,加入小组>>
176 浏览 0 评论
946 浏览 0 评论
1674 浏览 0 评论
请问一下我想用ESP8685直接替换ESP8266而不用写程序,可以让ESP8685直接通过之前ESP8266的外挂的flash运行程序吗
1334 浏览 1 评论
1234 浏览 1 评论
为blufi_device设置自定义名称,但是无法修改,为什么?
1254浏览 4评论
请问ESP32-S2-WROOM怎么获得ESP32-S2外接FLASH的唯一序列号?
928浏览 3评论
2340浏览 3评论
ESP-IDF的VScode插件的build按钮点击会报错的原因?
2528浏览 3评论
ESP-Jumpstart例程中第5个工程:5_cloud连接报错是哪里的问题?
1052浏览 2评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-3 04:59 , Processed in 0.620572 second(s), Total 75, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
372
