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

Adafruit I2S MEMS Microphone Breakout with the NRF9160 DK

Hello,

I am working on a project where I can have Voice over IP on the NRF9160 DK. I am now working with a I2S microphone (https://www.adafruit.com/product/3421) at the moment I have trouble programming I2S. I read the I2S documentation on the zephyr website but I have still trouble understanding it and there is also no example where I can look at. I don't know how to setup the struct device (https://docs.zephyrproject.org/2.0.0/reference/peripherals/i2s.html?highlight=i2s#) that you use in the functions to setup i2s and read/write the buffer. I also don't know which pin i have to connect to the microphone, because the pin names are not the same or can i just connect  to any pin and write in the code to use that pin? If sombody has an I2S example I would really appreciate that. I also need to find a speaker that I can use any suggestions?

Thank you in advance

  • Hi Martin,

    I changed the files and the i2s_configure still doesn't work. I found out that the device_get_binding returns a null pointer so the i2s_device is probably the problem. Is it possible that I have the wrong driver name or that i2s is still disabled. I enabled i2s in the prj.conf CONFIG_I2S=y so that shouldn't be the problem.

    Thank you in advance

  • I am using now the nrfx_i2s driver. I asked a question about the i2s in this thread   https://devzone.nordicsemi.com/f/nordic-q-a/60256/i2s-on-nrf9160 can you please check it out.

    thank you

  • Hi Martin,

    So I am using now the nrfx_i2s driver I changed the code and I don't receive any data. I think that the problem is with the datahandler. The microphone(https://www.adafruit.com/product/3421) works with a raspberry pi so the microphone works.I don't know how to fix this. I connected
    LRCL with pin 8
    DOUT with 9
    BCLK with pin 10

    #include <nrf.h>
    #include <zephyr.h>
    #include <device.h>
    #include <sys/printk.h>
    #include <stdbool.h>
    #include <nrfx_i2s.h>
    #include <string.h>
    
    #include "microphone.h"
    #include "button.h"
    #include "udp.h"
    
    #define  I2S_BUFFER_SIZE 1024
    #define  SCK_PIN    10 
    #define  SDIN_PIN   9
    #define  LRCK_PIN   8
    #define  MCK_PIN    7
    #define  SDOUT_PIN  6 
    
    int counter;
    static uint32_t rx_buffer[I2S_BUFFER_SIZE]={0};
    static uint32_t tx_buffer[I2S_BUFFER_SIZE]={0};
    static nrfx_i2s_buffers_t buffer;   
     
    ISR_DIRECT_DECLARE(i2s_isr_handler) 
    {
      nrfx_i2s_irq_handler();
      ISR_DIRECT_PM();
    
      return 1; 
    }
    
    static void data_handler(nrfx_i2s_buffers_t const * p_released, uint32_t status)
    { 
      if (NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED == status)
      {
        printk("%u\n",status);
        nrfx_err_t err = nrfx_i2s_next_buffers_set(&buffer);
        if (err != NRFX_SUCCESS ) {
            printk("next buffer failed with error code:%d\n",err);
          } 
      }
    
      if(p_released != NULL){
        if (p_released->p_rx_buffer != NULL)
        {
            //uint8_t* data=p_released->p_rx_buffer;
            //data[0] == p_released->p_rx_buffer[0]
            uint8_t data[I2S_BUFFER_SIZE]={0};
            memcpy(data,p_released->p_rx_buffer, sizeof(p_released->p_rx_buffer));
            for(int i=0; i <1024; i++)
            {
                printk("data: 0x%hhX\n",data[i]);
                printk("data2:0x%hhX\n",p_released->p_rx_buffer[i]);
            }
          }
        }
      }
    }
    
    void recordaudio(void)
    {
      printk("Start i2s configuration\n");
      nrfx_err_t err;
      uint16_t buffer_size=2048;
      nrfx_i2s_config_t config = NRFX_I2S_DEFAULT_CONFIG(SCK_PIN,LRCK_PIN,MCK_PIN,SDOUT_PIN,SDIN_PIN);
      
      buffer.p_rx_buffer=rx_buffer;
      buffer.p_tx_buffer=tx_buffer;
    
     //config.irq_priority = NRFX_I2S_DEFAULT_CONFIG_IRQ_PRIORITY;
    // config.mode = NRF_I2S_MODE_MASTER;
    // config.mck_setup = NRF_I2S_MCK_32MDIV8;
    // config.channels = NRF_I2S_CHANNELS_LEFT;
    // config.sample_width = NRF_I2S_SWIDTH_16BIT;
    // config.ratio = NRF_I2S_RATIO_32X;
    // config.format = NRF_I2S_FORMAT_I2S;
    // config.alignment=NRF_I2S_ALIGN_LEFT;
    //  
     IRQ_DIRECT_CONNECT(I2S_IRQn, 0,i2s_isr_handler, 0);
    
      err = nrfx_i2s_init(&config, data_handler);
      if (err != NRFX_SUCCESS)
      {
          printk("i2s init failed:%d\n",err);
      }
      printk("i2s_start\n");
      err=nrfx_i2s_start(&buffer,buffer_size, 0);
      if(err!=NRFX_SUCCESS )
        {
         printk("i2s start failed with error:%d\n",err);
        }
      while(1)
         {
          printk("recording\n");
          k_sleep(2000);
         }
        printk("\n stop recording \n");
        nrfx_i2s_stop();
        nrfx_i2s_uninit();
    }

  • Hi Nahom,

    Please try to assign other pins since 8 and 9 are used on switch 1 & switch 2 on the nrf91DK.

    Look at the documentation at which pins that are available: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf91_dk%2FUG%2Fnrf91_DK%2Fif_connector.html

Related