I2S example code

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

Re: I2S example code

Post by victor_pv » Fri Apr 21, 2017 5:47 am

ChrisMicro wrote:The MAX98357a seems to need a quite accurate timing.
The timing of the code example above ( timer interrupt triggers SPI ) seems to be not sufficient for this chip.
The bit sequence needs to start 1 bit delayed ( relating to the I2S specs ) which seems to me that it can not be done with DMA.
Agreed, I think it would only works for left justified mode, like the PT8211.

I don't know all the SPI modes though, so I dont know if there is any way to configure the spi peripheral to send a clk cycle before the first bit.

EDIT: Looks like the MAX98357b supports left justified mode.

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: I2S example code

Post by ChrisMicro » Fri Apr 21, 2017 8:00 pm

EDIT: Looks like the MAX98357b supports left justified mode.
Well, yes ... but the breakout board from Adafruit is unfortunately the 'A' version ... and I have it ...
https://developer.mbed.org/users/Plugo/ ... -adafruit/

Ok, let's delay the problem for some years ..

victor_pv
Posts: 1746
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Fri Apr 21, 2017 8:24 pm

ChrisMicro wrote:
EDIT: Looks like the MAX98357b supports left justified mode.
Well, yes ... but the breakout board from Adafruit is unfortunately the 'A' version ... and I have it ...
https://developer.mbed.org/users/Plugo/ ... -adafruit/

Ok, let's delay the problem for some years ..
You could loose 1 bit of resolution if you just shift the words 1 bit.


Now you output that in the SPI. The first 0 during the first clock cycle is discarded, next the MAX will take all other 15 bits and take them as the MSB of that word, but is still waiting for 1 BIT right?
Timer overflows, and the SPI sends the next 16bits, with the MSB set as 0 again. The MAX will take that first bit to complete the word for the other channel, and then take the next 15 for the current one.
That goes on and on until you stop playing.
So you actually lose the LSB, because it will be filled with the 1st bit sent out for the next word.
I know my explanation is completely clear, but look at figure 6 in the max98357a datasheet, and then imagine D15 was actually sent be the SPI as the second bit in the transfer. So if you shift every word by one, they will all fit in.

MSB ------------- LSB
1111111111111111
Shift it right:
0111111111111111 (LSB bit is lost)
If you put keep sending your data shifted 1 bit, you would get something like this right?
0111111111111111 0111111111111111 0111111111111111 0111111111111111....
Now, because the DAC actually expects the first bit in the 2nd clock, and the last bit in the first clock after the LRClk togles, the DAC will take them as this:
0 - 111111111111111 0 -1111111111111110 - 1111111111111110 - 1111111111111110....
0(lost) - word 1 - word2 - word 3 - word 4

So effectively you just made a 0 in the LSB. You get 15 bits of resolution out of 16

EDIT:
Or you can just order an RCT board from ebay or aliexpress ;)

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: I2S example code

Post by ChrisMicro » Sat Apr 22, 2017 7:33 am

Or you can just order an RCT board from ebay or aliexpress ;)
Yes, sometimes I also tend to solve software problems by hardware ;-)

Here is a nice one, but it is made for self-soldering:
https://www.pjrc.com/store/pt8211_kit.html

victor_pv
Posts: 1746
Joined: Mon Apr 27, 2015 12:12 pm

Re: I2S example code

Post by victor_pv » Sat Apr 22, 2017 3:16 pm

ChrisMicro wrote:
Or you can just order an RCT board from ebay or aliexpress ;)
Yes, sometimes I also tend to solve software problems by hardware ;-)

Here is a nice one, but it is made for self-soldering:
https://www.pjrc.com/store/pt8211_kit.html
That's nice, if I had found it before I bought a bunch of pt8211 and DIP to SOP little pcbs I would have bought that instead.
Soldering the chip wasn't that much trouble.

The best board I think would be one like that + a small amplifier all in a single PCB.

Post Reply