Skip to content

I2S driver doesn't work (GIT8266O-558) #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
QB4-dev opened this issue Sep 28, 2020 · 7 comments
Closed

I2S driver doesn't work (GIT8266O-558) #981

QB4-dev opened this issue Sep 28, 2020 · 7 comments

Comments

@QB4-dev
Copy link

QB4-dev commented Sep 28, 2020

Environment

  • Development Kit: NodeMCU + PCM1502A I2S DAC
  • IDF version (git rev-parse --short HEAD to get the commit id.): Release/v3.3 (GIT8266O-490) #917 (release/v3.3) as well as master
    //483a5a475c7afdf3336c66fa279c70de4bb8b750
  • Development Env: Eclipse
  • Operating System: Ubuntu
  • Power Supply: USB + external 5V

Problem Description

I have no output from on I2S. I'am using official example:
https://github.com/espressif/ESP8266_RTOS_SDK/tree/master/examples/peripherals/i2s

Using i2s_write( ) function is hanging until timeout occurs without writing data into DMA Queue

i2s_write(I2S_NUM, samples_data, ((bits + 8) / 16)*SAMPLE_PER_CYCLE * 4, &i2s_bytes_write, 100);

Every time i2s_bytes_write is 0

Expected Behavior

Triangle and sine 100Hz wave on I2S DAC output

Actual Behavior

When Debug message level is set to INFO, serial monitor output is as expected:

Test bits=24 free mem=78188, written data=2880
I (5655) i2s: DMA Malloc info, datalen=blocksize=480, dma_buf_count=6

Test bits=16 free mem=78188, written data=1440
I (10735) i2s: DMA Malloc info, datalen=blocksize=240, dma_buf_count=6

Test bits=24 free mem=78188, written data=2880
I (15835) i2s: DMA Malloc info, datalen=blocksize=480, dma_buf_count=6

Test bits=16 free mem=78188, written data=1440
I (20915) i2s: DMA Malloc info, datalen=blocksize=240, dma_buf_count=6

but only reason why in this example is running is break on timeout in `xQueueReceive'

while (size > 0) {
if (p_i2s_obj[i2s_num]->tx->rw_pos == p_i2s_obj[i2s_num]->tx->buf_size || p_i2s_obj[i2s_num]->tx->curr_ptr == NULL) {
if (xQueueReceive(p_i2s_obj[i2s_num]->tx->queue, &p_i2s_obj[i2s_num]->tx->curr_ptr, ticks_to_wait) == pdFALSE) {
break;
}
p_i2s_obj[i2s_num]->tx->rw_pos = 0;
}
ESP_LOGD(I2S_TAG, "size: %d, rw_pos: %d, buf_size: %d, curr_ptr: %d", size, p_i2s_obj[i2s_num]->tx->rw_pos, p_i2s_obj[i2s_num]->tx->buf_size, (int)p_i2s_obj[i2s_num]->tx->curr_ptr);
data_ptr = (char *)p_i2s_obj[i2s_num]->tx->curr_ptr;
data_ptr += p_i2s_obj[i2s_num]->tx->rw_pos;
bytes_can_write = p_i2s_obj[i2s_num]->tx->buf_size - p_i2s_obj[i2s_num]->tx->rw_pos;
if (bytes_can_write > size) {
bytes_can_write = size;
}
memcpy(data_ptr, src_byte, bytes_can_write);
size -= bytes_can_write;
src_byte += bytes_can_write;
p_i2s_obj[i2s_num]->tx->rw_pos += bytes_can_write;
(*bytes_written) += bytes_can_write;
}

If You pass portMAX_DELAY as ticks_to_wait function i2s_bytes_write will hang forever

When DEBUG info is enabled there should be info about samples write

ESP_LOGD(I2S_TAG, "size: %d, rw_pos: %d, buf_size: %d, curr_ptr: %d", size, p_i2s_obj[i2s_num]->tx->rw_pos, p_i2s_obj[i2s_num]->tx->buf_size, (int)p_i2s_obj[i2s_num]->tx->curr_ptr);

like :

D (20915) i2s: size: 256, rw_pos: 16 , buf_size: 256, curr_ptr: 256

but there is no output like that.

Steps to repropduce

  1. Compile and run i2s example: https://github.com/espressif/ESP8266_RTOS_SDK/tree/master/examples/peripherals/i2s
  2. Set log verbosity to DEBUG
  3. Run again 'monitor` with debug info: no DMA write
@github-actions github-actions bot changed the title I2S driver doesn't work I2S driver doesn't work (GIT8266O-558) Sep 28, 2020
@doragasu
Copy link

I can confirm this problem on a nodemcu, branch is release/v3.3, commit 210943a9

Please provide a fix or workaround.

@doragasu
Copy link

Tried also with latest release/v3.3 and latest master (with gcc 8.2) and the problem persists.

@doragasu
Copy link

I have plugged a scope and it seems code is working! The problem is that on the nodemcu, the GPIO3 pin is connected to the CP2102 TX pin through a 470 ohm resistor, and it is trying to pull the pin high. This causes problems on this specific board. We would need to test this on a different board that has this pin unconnected, or at least not connected to another output.

@QB4-dev
Copy link
Author

QB4-dev commented Dec 1, 2020

@doragasu
Yup. You are right, when DAC is connected to NodeMCU I2S works without issues but if logic analyzer only is connected GPIO3 line is pulled to high. So I can confirm that this is board connected issue.

@QB4-dev QB4-dev closed this as completed Dec 1, 2020
@flytobluesky
Copy link

I can confirm this problem on a nodemcu, branch is release/v3.4 , the 470 ohm resistors between ESP12E and cp2102 is removed, I2S is still not working properly. GPIO2 GPIO3 and GPIO15 have no wave.

Steps to repropduce
Compile and run i2s example: https://github.com/espressif/ESP8266_RTOS_SDK/tree/master/examples/peripherals/i2s

@papadeltasierra
Copy link

I'm not seeing this work with an ESP8266-01 device either. The "bytes_write" value is always zero. DMA does work on this device because I've previously (3-4 years ago?) had this working having reworked the old freertos code myself.

@papadeltasierra
Copy link

As this appears to be closed, I'm going to open a new issue, referencing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants