我正在使用NRF5340DK调试I2S功能。我完成了I2S的初始化,并打开了TASKS_START.我通过示波器看见MCK和LRCK都程序产生了理想的波形。但是SCK和SDOUT都没有波形产生。我还发现打开TASKS_START后,事件EVENT_TXPTRUPD、EVENTS_RXPTRUPD和EVENTS_FRAMESTART依次被触发一次,但是后面触发事件再也没有发生。
请问我应该如何解决这个问题。谢谢。
I am using NRF5340DK to debug I2S functions. I completed the initialization of I2S and opened TASKS_START. I saw through the oscilloscope that both MCK and LRCK programs produced ideal waveforms. But neither SCK nor SDOUT has a waveform generated. I also found that after opening TASKS_START, the events EVENT_TXPTRUPD, EVENTS_RXPTRUPD and EVENTS_FRAMESTART were triggered once in turn, but the subsequent triggering event never happened again.
How can I solve this problem. Thank you.
/*
* Copyright (c) 2020 Antmicro <www.antmicro.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <sys/printk.h>
#include <drivers/i2s.h>
#include <stdlib.h>
#include <string.h>
#include <nrf_rpc.h>
#include "nrfx_i2s.h"
#include "rpc.h"
#include <drivers/gpio.h>
#include <hal/nrf_gpio.h>
#include <hal/nrf_gpiote.h>
#include <nrfx_gpiote.h>
#include <drivers/clock_control.h>
#include <drivers/clock_control/nrf_clock_control.h>
#define AUDIO_SAMPLE_FREQ (48000)
#define AUDIO_SAMPLES_PER_CH_PER_FRAME (128)
#define AUDIO_NUM_CHANNELS (2)
#define AUDIO_SAMPLES_PER_FRAME \
(AUDIO_SAMPLES_PER_CH_PER_FRAME * AUDIO_NUM_CHANNELS)
#define AUDIO_SAMPLE_BYTES (3)
#define AUDIO_SAMPLE_BIT_WIDTH (24)
#define AUDIO_FRAME_BUF_BYTES (AUDIO_SAMPLES_PER_FRAME * AUDIO_SAMPLE_BYTES)
#define I2S_PLAY_BUF_COUNT 100
#define RPC_BUFFER_LEN 252
static const struct device *host_i2s_rx_dev;
static const struct device *host_i2s_tx_dev;
static struct k_mem_slab i2s_rx_mem_slab;
static struct k_mem_slab i2s_tx_mem_slab;
static char rx_buffers[AUDIO_FRAME_BUF_BYTES * I2S_PLAY_BUF_COUNT];
static char tx_buffer[AUDIO_FRAME_BUF_BYTES * I2S_PLAY_BUF_COUNT];
static struct i2s_config i2s_rx_cfg;
static struct i2s_config i2s_tx_cfg;
static int ret;
#define I2S_DATA_BLOCK_WORDS 512
static uint32_t m_buffer_rx[2][I2S_DATA_BLOCK_WORDS];
static uint32_t m_buffer_tx[2][I2S_DATA_BLOCK_WORDS];
static uint32_t * volatile mp_block_to_fill = NULL;
static uint32_t const * volatile mp_block_to_check = NULL;
void iis_user_irq_handler(void)
{
uint8_t temp = 0;
if (nrf_i2s_event_check(NRF_I2S0, NRF_I2S_EVENT_TXPTRUPD))
{
nrf_i2s_event_clear(NRF_I2S0, NRF_I2S_EVENT_TXPTRUPD);
temp = 1;
}
if (nrf_i2s_event_check(NRF_I2S0, NRF_I2S_EVENT_RXPTRUPD))
{
nrf_i2s_event_clear(NRF_I2S0, NRF_I2S_EVENT_RXPTRUPD);
temp = 2;
}
if (nrf_i2s_event_check(NRF_I2S0, NRF_I2S_EVENT_STOPPED))
{
nrf_i2s_event_clear(NRF_I2S0, NRF_I2S_EVENT_STOPPED);
temp = 3;
}
if (nrf_i2s_event_check(NRF_I2S0, NRF_I2S_EVENT_FRAMESTART))
{
nrf_i2s_event_clear(NRF_I2S0, NRF_I2S_EVENT_FRAMESTART);
temp = 4;
}
}
static void iis_init(void)
{
nrfx_i2s_config_t config;
config.sck_pin = NRF_GPIO_PIN_MAP(0,19);
config.lrck_pin = NRF_GPIO_PIN_MAP(0,21);
config.mck_pin = NRF_GPIO_PIN_MAP(1,4);
config.sdout_pin = NRF_GPIO_PIN_MAP(1,8);
config.sdin_pin = NRF_GPIO_PIN_MAP(1,6);
config.irq_priority = 100;
config.mode = NRF_I2S_MODE_MASTER;
config.format = NRF_I2S_FORMAT_I2S;
config.alignment = NRF_I2S_ALIGN_RIGHT;
config.sample_width = NRF_I2S_SWIDTH_16BIT;
config.channels = NRF_I2S_CHANNELS_STEREO;
config.mck_setup = NRF_I2S_MCK_32MDIV8;
config.ratio = NRF_I2S_RATIO_192X;
config.clksrc = NRF_I2S_CLKSRC_PCLK32M;
config.enable_bypass = false;
if ( nrfx_i2s_init(&config, iis_data_handler) == NRFX_SUCCESS )
{
printk("IIS INIT SUCCESSED\r\n");
}
nrf_gpio_cfg(NRF_GPIO_PIN_MAP(0,21),NRF_GPIO_PIN_DIR_OUTPUT,NRF_GPIO_PIN_INPUT_DISCONNECT,NRF_GPIO_PIN_NOPULL,NRF_GPIO_PIN_H0H1,NRF_GPIO_PIN_NOSENSE);
nrf_gpio_cfg(NRF_GPIO_PIN_MAP(1,4),NRF_GPIO_PIN_DIR_OUTPUT,NRF_GPIO_PIN_INPUT_DISCONNECT,NRF_GPIO_PIN_NOPULL,NRF_GPIO_PIN_H0H1,NRF_GPIO_PIN_NOSENSE);
IRQ_DIRECT_CONNECT(I2S0_IRQn, 100, iis_user_irq_handler, 0);
}
void main(void)
{
uint8_t temp = 0;
uint8_t rpc_buffer[RPC_BUFFER_LEN];
int err;
iis_init();
nrfx_i2s_buffers_t const initial_buffers = {
.p_tx_buffer = m_buffer_tx[0],
.p_rx_buffer = m_buffer_rx[0],
};
if ( nrfx_i2s_start(&initial_buffers, I2S_DATA_BLOCK_WORDS, 0) == NRFX_SUCCESS )
{
printk("IIS START SUCCESSED\r\n");
}
while(1)
{
k_sleep(K_MSEC(10));
}
}