nRF52840 I2S write failed -11

Hello,

I am using two nrf52840 DKs to test ble transmission and i2s output. The nRF Connect SDK I use is v2.6.0.

Both of them are ble connected. One sends data to the other through ble, and the other receives the data and outputs it to i2s.

The i2s is set to write data every 100ms.

During the test, I found that every time i2s writes 100ms of data, it must do an I2S_TRIGGER_STOP, otherwise an error will occur.

Just like the code below, I must first do I2S_TRIGGER_START in each round, then write data to i2s tx, and finally I must do I2S_TRIGGER_STOP.

void i2s_send(void){
	int ret;
	memset(mem_block, 0, BLOCK_SIZE);
	ret = i2s_write(i2s_dev_tx, mem_block, BLOCK_SIZE);
	if (ret < 0) {
		LOG_ERR("Failed to write block %d", ret);
	}
	/* Put data into the tx buffer */
	for (int i = 0; i < 9600; i++) {
		((int16_t*)mem_block)[i] = (int16_t)data_buf_modify[i];
  	}
	ret = i2s_trigger(i2s_dev_tx, I2S_DIR_TX, I2S_TRIGGER_START);
	if (ret < 0) {
		LOG_ERR("Failed to trigger command I2S_TRIGGER_START on TX: %d\n", ret);
	}
	ret = i2s_write(i2s_dev_tx, mem_block, BLOCK_SIZE);
	if (ret < 0) {
		LOG_ERR("Failed to write data: %d", ret);
	}else{
		LOG_INF("Success to write data.");
	}
	ret = i2s_trigger(i2s_dev_tx, I2S_DIR_TX, I2S_TRIGGER_STOP);
	if (ret < 0) {
		LOG_ERR("Failed to trigger command I2S_TRIGGER_DRAIN on TX: %d\n", ret);
	}
}

This causes my i2s output to be noisy, which I think is due to the pause during playback.

But if I only do I2S_TRIGGER_START at the beginning, and then do not do I2S_TRIGGER_STOP after i2s write, but directly do the next round of i2s write, I will get the following error:

[00:00:00.395,660] <inf> central_test: Success to write data.
[00:00:00.395,660] <inf> central_test: Success to write data.
[00:00:00.396,026] <inf> central_test: Success to write data.
[00:00:00.396,057] <inf> central_test: Success to write data.
[00:00:00.496,856] <inf> central_test: Success to write data.
[00:00:01.496,948] <err> central_test: Failed to write data: -11
[00:00:02.497,100] <err> central_test: Failed to write data: -11
[00:00:03.497,253] <err> central_test: Failed to write data: -11
[00:00:04.497,375] <err> central_test: Failed to write data: -11

I encountered a similar problem in this post, and it has solved by replacing i2s_write with i2s_buf_write.

But after joining ble communication, I encountered the same problem and used the same solution to no avail.

I'm confused as to why there is this difference. Is it because nrf52840 cannot continuously do i2s write while receiving ble data? Is it necessary to stop i2s first and then start to write continuously?

Related