This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF5340DK I2S issue

Hi, guys

I am debugging the I2S feature on nRF340DK, when I completed the initialization of I2S pins configuration  and start I2S, the SCK,LRCK and MCLK pins can produced the waveforms. 

But there is no signals on sdout_pin.

The EVENT_TXPTRUPD and EVENTS_FRAMESTART event can be received normally.

And I also check this Devzone thread, but it still can't work.

(https://devzone.nordicsemi.com/f/nordic-q-a/75638/nrf5340-about-i2s-debugging)

Could anyone help me to fix it?

Thanks a lot!

#define I2S_DATA_BLOCK_SIZE 512

static nrfx_i2s_buffers_t initial_buffers;
static uint8_t m_buffer_rx[2][I2S_DATA_BLOCK_SIZE];
static uint8_t m_buffer_tx[2][I2S_DATA_BLOCK_SIZE];

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 nrfx_err_t i2s_init()
{
    nrfx_i2s_config_t config;
    config.sck_pin        = NRF_GPIO_PIN_MAP(0,6); //sclk
    config.lrck_pin       = NRF_GPIO_PIN_MAP(0,7); //lrck
    config.mck_pin        = NRF_GPIO_PIN_MAP(1,4);  //mclk
    config.sdout_pin      = NRF_GPIO_PIN_MAP(1,8); //txsda
    config.sdin_pin       = NRF_GPIO_PIN_MAP(1,6); //rxsda
    config.irq_priority   = 100;
    config.mode           = NRF_I2S_MODE_MASTER;

    config.format         = NRF_I2S_FORMAT_I2S;
    config.alignment      = NRF_I2S_ALIGN_LEFT;
    config.sample_width   = NRF_I2S_SWIDTH_16BIT;
    config.channels       = NRF_I2S_CHANNELS_STEREO;
    config.mck_setup      = 0x66666000;
    config.ratio          = NRF_I2S_RATIO_128X;

    config.clksrc         = NRF_I2S_CLKSRC_ACLK; 
    config.enable_bypass  = false;

    nrfx_err_t err_code = nrfx_i2s_init(&config, data_handler);
    if (err_code != NRFX_SUCCESS)
    {
        printk("I2S init error\n");
        return err_code;
    }
    IRQ_DIRECT_CONNECT(I2S0_IRQn, 0, iis_user_irq_handler, 0);
    return err_code;
}

void main(void)
{
    
    nrfx_err_t err1;
    err1 = i2s_init();
    if (err1 != NRFX_SUCCESS)
    {
        return;
    }
 
    memset(m_buffer_tx[0], 0x00, I2S_DATA_BLOCK_SIZE);
    memcpy(m_buffer_tx[0], WaveData+AUIDO_START_ADDRESS, I2S_DATA_BLOCK_SIZE);

    initial_buffers.p_tx_buffer = m_buffer_tx[0];
    initial_buffers.p_rx_buffer = NULL;
    nrfx_err_t err_code = nrfx_i2s_start(&initial_buffers, I2S_DATA_BLOCK_SIZE, 0); //start send
    if (err_code != NRFX_SUCCESS) {
	printk("Error: %x\n", err_code);
    }

    while (1)
    {
        k_sleep(K_MSEC(PAUSE_TIME));
    }
}

Related