I2S example code

Post your cool example code here.
Post Reply
victor_pv
Posts: 1448
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Mon Sep 07, 2015 2:00 pm

madias wrote:
I would set all the DMA stuff, including the DMA enable, somewhere else, so
bb_peri_set_bit(&dev->regs->CR2, SPI_CR2_TXDMAEN_BIT, 1); // DMA enable
should not be there.
Yes, sorry, this example is from my test code, I forgot to eliminate the DMA line.

Effect pedal and DUE: I know that stuff: real 12-bit crunchy sound! :) Another thing: For uncomplicated effects like simple delay you wont have enough RAM. I read, that the CMSIS DSP library runs not only on M4, but on M3...maybe a good starting point for porting it (I know that on energia/TI - Tiva somebody ported it)
edit: found it! https://github.com/sumotoy/CMSIS-librar ... a-LM4F-mcu
About the RAM, it depends though, we could always add an SPI RAM, or an FSMC RAM and have plenty ;)

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: I2S example code

Post by Vassilis » Mon Sep 07, 2015 3:36 pm

madias wrote:
Vassilis wrote:
madias wrote:...vasillis would be the person.
Matthias, may I have a working (latest) copy of your I2S library to make some tests on my VET6 board ?
Vassilis: I've managed it that no changes are needed within spi.c or spi.h!

Please use my code as *.zip and please tell me if you are getting compiling errors! (Maybe I missed some #defines, but I tried it with a "clean" repo)
The test code is for a PT8211 DAC sinus right and saw up left ---> edit: I use SPI3! In the configuration there is no Master Clock enabled.
and edit 2 --> sorry for not cleaning up the code :)
I connected the PT8211

STM32F103VET6 <--> PT8211
PB3 <--> BCK
PA15 <--> WS
PB5 <--> DIN

but I see only a sawtooth wave at 374 Hz on the right channel. Not a sine wave.
Which are the STM32 pins you used ?

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: I2S example code

Post by madias » Mon Sep 07, 2015 3:52 pm

connections are the same, but on a RET6 board (shouldn't be a different).
What's on the left channel?
edit: sine is on the left channel! I messed up my wiring stuff...
Last edited by madias on Mon Sep 07, 2015 3:56 pm, edited 1 time in total.

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: I2S example code

Post by Vassilis » Mon Sep 07, 2015 3:55 pm

I comment-out the line 128 and 134 and it worked:

Code: Select all

if (dma_get_isr_bits( DMA2, DMA_CH2) == 3)

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: I2S example code

Post by madias » Mon Sep 07, 2015 3:58 pm

yes, but
i2s_buffer[0]= left channel and
i2s_buffer[1]= right channel
with eleminating the if (dma_get_isr_bits( DMA2, DMA_CH2) == 3) you eleminate the right/left stuff! :)

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: I2S example code

Post by Vassilis » Mon Sep 07, 2015 4:01 pm

By disabling those lines I saw the Sine wave on the Left channel and the Sawtooth wave on the Right channel simultaneously.

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: I2S example code

Post by madias » Mon Sep 07, 2015 4:08 pm

Yes, but you fill up the buffer[0] and [1] every time, so twice at it would be needed.
I set up a buffer with [2] and the "if" in the function
if (dma_get_isr_bits( DMA2, DMA_CH2) == 3)
triggers every "half transfer finished". So it fills up on first interrupt the buffer[0]n and on the next buffer[1]
But maybe I missed/messed something. But can you use my uncorrected example? Strange, that this is working on my place but not on yours...

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: I2S example code

Post by Vassilis » Mon Sep 07, 2015 4:12 pm

I will check again the code. Maybe there is some problem with my current stm32duino repo.

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: I2S example code

Post by madias » Mon Sep 07, 2015 4:28 pm

ok 374 hz is much too fast: 374x256=95744, but it should be 47872

madias
Posts: 813
Joined: Mon Apr 27, 2015 11:26 am
Location: Vienna, Austria

Re: I2S example code

Post by madias » Mon Sep 07, 2015 5:43 pm

ok, I've done a test LED within the dma IRQ:

Code: Select all

void DMAEvent() {
  if (dma_get_isr_bits( DMA2, DMA_CH2) == 3)
  {
    i2s_buffer[0]  = sine[wavecounter1] << 3; // half transfer
    wavecounter1++;
    flip=1;
  }
  else
  {
    i2s_buffer[1] = wavecounter2 << 8 ;
    wavecounter2++;
    flip=0;

  dma_clear_isr_bits(DMA2, DMA_CH2);
digitalWrite(LED,flip);
}
So you can easily see if left/right buffer is working! LED frequency should be 47.9khz

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest