Page 1 of 1

I2S DMA

Posted: Fri Apr 03, 2020 2:12 am
by small coke
I would like to inquire about using I2S to transmit voice. If using DMA, I want to generate an interrupt after the data is transmitted, but I do n’t see the DMA interrupt in the ESP32 technical manual, so I would like to ask the people who have used it to share it. Thank you very much for your experience!

Re: I2S DMA

Posted: Fri Apr 03, 2020 7:31 am
by Jakobsen
Hi Small Coke

I've done that - It is quite easy just wait for i2s_evt.type == I2S_EVENT_TX_DONE using xQueueReceive(i2s_queue, &i2s_evt, portMAX_DELAY);

The queue handle you will get from you driver install setup call
i2s_driver_install(0, &i2s_config, 10, &i2s_queue);

Let me know if you need more liquor to spice up you coke :-)

/J

Code: Select all

    ...
    double sweepPeriod     = 4;        // in sec  
    uint32_t i = 0;    
    i2s_event_t i2s_evt;
    sweepCnt = 0;
    freq = 50.0;   
    angleSpeed  = 2*M_PI*freq/sampleRate;
    
    while (1) {
        xQueueReceive(i2s_queue, &i2s_evt, portMAX_DELAY);
        if (i2s_evt.type == I2S_EVENT_TX_DONE) 
        { timer_cnt++;
          switch (mode) {
            case 0 : gate = 1;              // Continues 
                     break;
            case 1 :                  // Sweep
                     if (sweepCnt == 0 ) {
                       gate = 1;
                       freq = sweepStartFreq; 
                     } else 
                     { freq = freq * sweepSpeed;
                       angleSpeed = 2*M_PI*freq/sampleRate;
   xQueueReceive(i2s_queue, &i2s_evt, portMAX_DELAY);
        if (i2s_evt.type == I2S_EVENT_TX_DONE) 
                  }
                     if ( freq > sweepStopFreq )
                     { gate = 0;
                       //printf("sweepCnt : %d",sweepCnt);
                       sweepCnt = ( sweepCnt > sweepPeriod*lengthSig) ? 0 : sweepCnt + 1; 
                     } else 
                     { sweepCnt++; 
                     }
      ...

Re: I2S DMA

Posted: Fri Apr 03, 2020 12:51 pm
by small coke
Thank you very much!I feel you are right, I already have ideas! :D

Re: I2S DMA

Posted: Sat Apr 04, 2020 6:42 am
by small coke
Sorry, I still have some problems. I had some ideas according to your statement before, but when I look back and continue to look at the code you provided, I do n’t know if I did n’t understand it or if your code is incomplete. In normal logic, I think your code is missing some braces. Forgive me for being a little white. There may be some offenses between words, sorry! :roll:

Re: I2S DMA

Posted: Sat Apr 04, 2020 8:04 pm
by Jakobsen
Missing a lot ...

It is only a couple of lines from a signal generator component.

You can check out the full project from the repo :
https://github.com/jorgenkraghjakobsen/sig_gen.git

/j