I want to control two RGB LED strips with I2S with different GPIO. Not able to figure out how to achieve it. While trying to initialize by separate buffers and data handler functions, it gets breakpoint after err_code = nrf_drv_i2s_init(&config, i2s_data_handler_right);. Individually, each works fine.
Here are the PIN and buffers' declarations.
#define leds_l_pin 17 #define leds_r_pin 27 static uint32_t m_buffer_tx_left[i2s_buffer_size]; static uint32_t m_buffer_tx_right[i2s_buffer_size]; static uint32_t * volatile mp_block_to_fill_left = NULL; static uint32_t * volatile mp_block_to_fill_right = NULL;
Here is the initializing function for both left and right LEDs.
void i2s_init_left()
{
uint32_t err_code = NRF_SUCCESS;
nrf_drv_i2s_config_t config = NRF_DRV_I2S_DEFAULT_CONFIG;
config.sdin_pin = NRFX_I2S_PIN_NOT_USED;
config.sdout_pin = leds_l_pin;
config.mck_setup = NRF_I2S_MCK_32MDIV10;
config.ratio = NRF_I2S_RATIO_32X;
config.channels = NRF_I2S_CHANNELS_STEREO;
err_code = nrf_drv_i2s_init(&config, i2s_data_handler_left);
APP_ERROR_CHECK(err_code);
nrf_drv_i2s_buffers_t const initial_buffers_left =
{
.p_tx_buffer = m_buffer_tx_left
};
err_code = nrf_drv_i2s_start(&initial_buffers_left, i2s_buffer_size, 0);
APP_ERROR_CHECK(err_code);
}
void i2s_init_right()
{
uint32_t err_code = NRF_SUCCESS;
nrf_drv_i2s_config_t config = NRF_DRV_I2S_DEFAULT_CONFIG;
config.sdin_pin = NRFX_I2S_PIN_NOT_USED;
config.sdout_pin = leds_r_pin;
config.mck_setup = NRF_I2S_MCK_32MDIV10;
config.ratio = NRF_I2S_RATIO_32X;
config.channels = NRF_I2S_CHANNELS_STEREO;
err_code = nrf_drv_i2s_init(&config, i2s_data_handler_right);
APP_ERROR_CHECK(err_code);
nrf_drv_i2s_buffers_t const initial_buffers_right =
{
.p_tx_buffer = m_buffer_tx_right
};
err_code = nrf_drv_i2s_start(&initial_buffers_right, i2s_buffer_size, 0);
APP_ERROR_CHECK(err_code);
}
void init_i2s_func(){
i2s_init_left();
i2s_init_right();
}
Here are the handler functions.
void i2s_data_handler_left(nrf_drv_i2s_buffers_t const * p_released,
uint32_t status)
{
ret_code_t err_code;
ASSERT(p_released);
if (!(status & NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED))
{
return;
}
if (!p_released->p_rx_buffer)
{
nrf_drv_i2s_buffers_t const next_buffers = {
.p_tx_buffer = m_buffer_tx_left,
};
err_code = nrf_drv_i2s_next_buffers_set(&next_buffers);
APP_ERROR_CHECK(err_code);
mp_block_to_fill_left = m_buffer_tx_left;
}
else
{
err_code = nrf_drv_i2s_next_buffers_set(p_released);
APP_ERROR_CHECK(err_code);
mp_block_to_fill_left = (uint32_t *)p_released->p_tx_buffer;
}
}
void i2s_data_handler_right(nrf_drv_i2s_buffers_t const * p_released,
uint32_t status)
{
ret_code_t err_code;
ASSERT(p_released);
if (!(status & NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED))
{
return;
}
if (!p_released->p_rx_buffer)
{
nrf_drv_i2s_buffers_t const next_buffers = {
.p_tx_buffer = m_buffer_tx_right,
};
err_code = nrf_drv_i2s_next_buffers_set(&next_buffers);
APP_ERROR_CHECK(err_code);
mp_block_to_fill_right = m_buffer_tx_right;
}
else
{
err_code = nrf_drv_i2s_next_buffers_set(p_released);
APP_ERROR_CHECK(err_code);
mp_block_to_fill_right = (uint32_t *)p_released->p_tx_buffer;
}
}
Thanks!