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

How to read I2S configuration and print in UART using NRF52-DK ?

Hello,

I have an analogue audio mic connected to external ADC. The external ADC can give an output of 16bit, 20bits, 24bits and 32 bits I2S data. I have configured to send 20 bit as I2S output.

To enable the I2S communication between the ADC and NRF52 I use below configuration.

    config.sdin_pin  = I2S_SDIN_PIN;
    config.sdout_pin = NRFX_I2S_PIN_NOT_USED;
    config.mck_pin   = NRFX_I2S_PIN_NOT_USED;
    config.mck_setup = NRF_I2S_MCK_32MDIV15;
    config.ratio     = NRF_I2S_RATIO_48X;
    config.format    = NRF_I2S_FORMAT_I2S;
    config.sample_width  = NRF_I2S_SWIDTH_24BIT;
    config.channels      = NRF_I2S_CHANNELS_STEREO;

In the SDK config, I have selected the pin of SDIN as 28. SCK - 31 , LRCK - 30.

While debugging, I watch the RX buffer of the nrf_I2S the data to check values most of the time starts as 0xFF8 or 0xFF9 or 0x00.

I understand that if the 24-bit I2S communication is chosen then when storing NRF stores it with  0xFF"24bit value".

1. Can I communicated with 20 bits from the ADC side or should I use only 16 or 24?

2. If 20 bits can be configured then should I expect the RX buffer data should always starting as 0xFF0"20bits value"? Because I want to store it in SD card. So I need to store the raw data to a WAV header. And the raw data should be removed of first 12 bits.

When I use NRF RTT to print the 32-bit value from RX buffer it seems like NRF LOG stuck in a loop. Without NRF LOG statement I can see that RX buffer updating each time I debug. Need a suggestion for this problem as well.

Thanks

Cecil

Parents
  • Can you suggest a solution for NRF LOG struck in a loop problem. I am print the whole buffer in a loop.

    static bool check_samples(uint32_t const * p_block)
    {
        // [each data word contains two 16-bit samples]
        uint16_t i;
        for (i = 0; i < I2S_DATA_BLOCK_WORDS; ++i)
        {
            uint32_t const * p_word = &p_block[i];
            uint32_t sample_actual = *p_word;
            NRF_LOG_INFO("P_word: 0x%x ",sample_actual);
            //Process data for SD card storage/ Uart print
        }
        NRF_LOG_INFO("%3u: OK", m_blocks_transferred);
        return true;
    }

  • Hello Cecil,

    where is NRF_LOG stuck in a loop problem? What do you mean by this? Do you mean that the logs doesn't print correctly, or that it prints forever in a loop, e.g. the loop:

    for (i = 0; i< I2S_DATA_BLOCK_WORDS; i++)

    loop doesn't finish?

    BR,

    Edvin

  •     NRF_LOG_INFO("%3u: OK", m_blocks_transferred);   

    struck at above line.

    The loop for (i = 0; i< I2S_DATA_BLOCK_WORDS; i++) doesn't finish because of this NRF_LOG problem.

  • I am not sure why it is stuck (?). Do you mean stuck, or actually struck?

    What does it look like? does NRF_LOG_INFO(); never return? If so, is it the first call to NRF_LOG_INFO, or after a while?

    Please note that NRF_LOG_INFO() doesn't print immediately to the log. The log is printed when NRF_LOG_PROCESS() is called later in your main loop. 

    Perhaps you can try to change:

    #define NRF_LOG_DEFERRED 1
    to
    #define NRF_LOG_DEFERRED 0

    in your sdk_config.h file. Does that help?

    If not, can you replicate the issue in a project that doesn't require any external components other than the DK, and upload it here?

    BR,

    Edvin

  • Currently I am using printf(); statement to print the buffer values. I think i can solve this NRF log problem later. My problem is the I2S data stored can't be verified. I printed all the values and used audacity to convert the raw data to an audio file. It seems it is always noise.  I am sure the ADC configuration is correct because I am using exact setup using raspberry pi.  Can you suggest on how I can handle the I2S data and confirm the received data is correct. 

Reply
  • Currently I am using printf(); statement to print the buffer values. I think i can solve this NRF log problem later. My problem is the I2S data stored can't be verified. I printed all the values and used audacity to convert the raw data to an audio file. It seems it is always noise.  I am sure the ADC configuration is correct because I am using exact setup using raspberry pi.  Can you suggest on how I can handle the I2S data and confirm the received data is correct. 

Children
Related