I2S

HI

I am using the I2S on the nRF52840DK I have constructed an array and all works well except once I start it , it continues to run, I cant get it to play the sample just once, how can I do this

Start Code

NRF_I2S->ENABLE = 1;

// Configure data pointer
NRF_I2S->TXD.PTR = (uint32_t)&sine_table2[0];
NRF_I2S->RXTXD.MAXCNT = sizeof(sine_table2) / sizeof(uint32_t);

NRF_I2S->TASKS_START = 1;

for (;;)
{

    __WFE();

}

Any assistance would be appreciated.

Kind Regards

David

Parents
  • Hi,

    The TXPTRUPD event will be generated every time RXTXD.MAXCNT number of transmitted data words has been sent. You can stop transmitting when this event is generated. Alternatively, you can use our driver which makes it much more easier to setup and use the I2S peripheral.

    regards

    Jared 

  • Hi Jared

    Thanks for getting back to me, can you please show me how I can intercept and use the TXPTRUPD event in __WFE (Sleep Mode) as I cant seem to find any details on how to do this.

    Kind Regards

    David

  • Hi,

    You're mixing the usage of the driver and writing directly to the peripheral. All calls that starts with NRF_I2S-> is omitting the driver and writing directly to the driver. I suggest that you clean up your code and remove all parts that write directly to the peripheral and only use the driver.

    regards

    Jared 

  • Hi 

    That is the problem, I don't know how to Write it using the driver.

    I found this code online and it worked but not for a single shot, you gave me the code with an interrupt handler as above but that doesn't work.

    The code you recommended (I2S example in the SDK),  does not use an interrupt handler I don't understand it.

    Regards

    David

  • Hi

    I have used the driver to config the device but I still have 4 lines of code that are bare bones can you please assist me in converting them to use the driver. Please bare in mind this is the first time I have used your product/code.  my code is below

    #define PIN_MCK (41) //P1.09
    #define PIN_BCLK (40) //P1.08
    #define PIN_LRCK (38) //P1.06
    #define PIN_SDOUT (39) //P1.07


    static void data_handler(nrf_drv_i2s_buffers_t const * p_released,uint32_t status)
    {

    }


    int main(void)
    {
    uint32_t err_code = NRF_SUCCESS;

    nrf_gpio_cfg_output(LED);
    nrf_gpio_cfg_input(Button, NRF_GPIO_PIN_PULLUP);

    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_i2s_config_t config = NRF_DRV_I2S_DEFAULT_CONFIG;

    config.sck_pin = PIN_BCLK;
    config.lrck_pin = PIN_LRCK;
    config.sdout_pin = PIN_SDOUT;

    config.mode = I2S_CONFIG_MODE_MODE_Master;
    config.sample_width = I2S_CONFIG_SWIDTH_SWIDTH_16BIT;

    config.mck_setup = NRF_I2S_MCK_32MDIV8;
    config.ratio = NRF_I2S_RATIO_512X;
    config.channels = NRF_I2S_CHANNELS_RIGHT;

    err_code = nrf_drv_i2s_init(&config, data_handler);
    APP_ERROR_CHECK(err_code);


    // sine_table2[8192] from sounds.h
    // Configure data pointer
    NRF_I2S->TXD.PTR = (uint32_t)&sine_table2[0];
    NRF_I2S->RXTXD.MAXCNT = sizeof(sine_table2) / sizeof(uint32_t);


    NRF_I2S->ENABLE = 1;
    NRF_I2S->TASKS_START = 1;


    for (;;)
    {
    __WFE();
    }


    }

    Regards

    David

  • Hi there,

    I agree that the example from the SDK might be too complicated for someone that is just starting using our products. The bare-metal example I shared earlier should worked as I did test it before I uploaded it. Regarding your code:

    DPJONES said:
    NRF_I2S->TXD.PTR = (uint32_t)&sine_table2[0];
    NRF_I2S->RXTXD.MAXCNT = sizeof(sine_table2) / sizeof(uint32_t);


    NRF_I2S->ENABLE = 1;
    NRF_I2S->TASKS_START = 1;

    This block should be replaced by calling nrf_drv_i2s_start() where you pass the buffer, the buffer size as parameters. At the end of the function it will start the transfer, by triggering the START task. 

    The data handler should be called when the peripheral has finished accessing the buffer. You can therefore stop the function when the handler is called. 

    regards

    Jared 

  • Hi Jared

    Here I have tried to use the nrf_drv_i2s_start  but  giving warnings my array is an int16_t  so have tried to cast, this seems to be what the function expects. 

    err_code = nrf_drv_i2s_start((uint32_t)sine_table2, 8192, 0);
    APP_ERROR_CHECK(err_code);

    Here are the warnings.

    Can you please advice where I am going wrong.

    Regards

    David

Reply Children
Related