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

Getting i2s to work...

Hi,

I'd like to output some audio data through i2s. It's quite easy to understand your examples provided on infocenter, however, I can't get my code to work.

Here is what I do:

#define TX_BUFFER_SIZE    8                /* Length of transmit buffer, specified in 32-bit words */
                                                  
static uint32_t   mTxBuffer[TX_BUFFER_SIZE];

//-------------------------------------------------------------------

void  soundInitialise (ASoundCompleteCallback pCB)
{
    nrf_drv_i2s_config_t  config = NRF_DRV_I2S_DEFAULT_CONFIG;

    nrf_drv_i2s_init    (&config, onTxPrepare);
    nrf_gpio_pin_clear  (SDMODE_PIN);
    nrf_gpio_cfg_output (SDMODE_PIN);
}


void  soundPlay ()
{
    nrf_gpio_pin_set  (SDMODE_PIN);

    nrf_drv_i2s_start (NULL, mTxBuffer, TX_BUFFER_SIZE, 0);
}


static void  onTxPrepare (uint32_t const *p_data_received,
                          uint32_t       *p_data_to_send,
                          uint16_t        number_of_words)
{
    if (p_data_received != NULL)
        ;

    if (p_data_to_send  != NULL)
    {
        if (mTuneTx >= mTuneStop)
        {
            nrf_drv_i2s_stop   ();
            nrf_gpio_pin_clear (SDMODE_PIN);

            return;
        }

        while (number_of_words)
        {
            if (mTuneTx < mTuneStop)
               *p_data_to_send = *mTuneTx;
            else
               *p_data_to_send = 0;

            number_of_words--;
            mTuneTx++;
        }
    }
}

As soon as I call soundPlay () the code jumps into onTxPrepare () where a HardFault exception occurs. Why?

Thanks for your assistance.

Parents Reply Children
No Data
Related