[SOLVED]Audio codec shield with Arduino Due

Re: Audio codec shield with Arduino Due

Postby youthreewire » Mon Jun 15, 2015 2:46 am

I set BYPASS=1 and it is working ,so we know that I2C is working but SPI(I2S) is not working for some reason.As you told me I wrote the code for SPI as this
Code: Select all
void TC3_Handler()
{
        TC_GetStatus(TC1, 0);

        temp = random(65535);
        temp = left_out;
        temp1 = right_out;
        temp_spi[0] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
        temp_spi[1] = SPI.transfer(10,lowByte(temp),SPI_CONTINUE);
        temp_spi[2] = SPI.transfer(10,highByte(temp1),SPI_CONTINUE);
        temp_spi[3] = SPI.transfer(10,lowByte(temp1),SPI_LAST);
        left_in - (temp_spi[0]<<8)|temp_spi[1];
        right_in = (temp_spi[2]<<8)|temp_spi[3];
}


So what am I doing wrong here.Also I could not use TIMER pin because I do not know to what GPIO pin it corresponds to.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Mon Jun 15, 2015 12:50 pm

awesome to hear that the i2c is working.

to use SPI (as compared to I2S), the SS pin needs to be toggled right at the beginning for a very specific amount of time. for both the uno and maple libraries, i had to hand tweak those parameters in assembly to get it right. i also had to use an oscilloscope to see what was happening. so, if you have an oscilloscope, you might be able to do this. but, this is not required for I2S, which i why i reccomend going that route.

also, the timer needs to be set up to count the number of pulses on the input pin. it looks like it is only setup to make a frequency in your code (44100).
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Wed Jun 17, 2015 3:21 am

I saw one fundamental difference.For atmega328 and atmega2560 the SPI_CLK_DIV was set to 2 which was putting it at 8Mhz but the function for Due was setting it to 4 Mhz.I will change this back to 8 mhz on the Due and check.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Wed Jun 17, 2015 3:59 am

Now I am able to get the SPI values but the sound output is like a crackling buzz in the headphones. I think it could be that the clock of Due is 84Mhz and clock divider for SPI is not a whole number at 10 for 8 mhz SPI clock.It is 10.5. Now I will boost the frequency to 96 and see if I get better values and the clock will be at 8mhz.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Wed Jun 17, 2015 10:59 am

SPI will not work unless you toggle the SS pin correctly. please read the datasheet for the WM8731:
http://wiki.openmusiclabs.com/wiki/Audi ... WM8731.pdf
page 35 - DSP mode, mode B.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Thu Jun 18, 2015 4:06 am

I think at 10.5 SPI clock divder the SS pin (which is pin10 in my code) is not toggling at the right frequnecy.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Thu Jun 18, 2015 10:59 am

it has nothing to do with SPI clock frequency. in standard SPI, SS goes low for the entire duration of the transmit. as you can see in the datasheet, you need it to go high at the start of the transmission, and then go low one clock cycle later.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Thu Jun 18, 2015 8:33 pm

This is the waveform that I am getting on the SS pin.
IMG_20150619_085456.jpg
IMG_20150619_085456.jpg (100.16 KiB) Viewed 7467 times

IMG_20150619_085450.jpg
Oscilloscope Due pin 10 SS .
IMG_20150619_085450.jpg (106.19 KiB) Viewed 7467 times
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Thu Jun 18, 2015 9:18 pm

The SS pin wave is at 13.5Khz. Sorry that was the wave duration not its frequcny.7.4Us is the pulse width.
Last edited by youthreewire on Thu Jun 18, 2015 10:34 pm, edited 2 times in total.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Thu Jun 18, 2015 9:22 pm

I was also able to set the SS pin wave at 11.6Us (pulse width) when I changed the SPI clock to 4 Mhz. So what I observed is as I am changing the SPI clock divider the SS pin wave is also changing its frequency which is expected.I think I need to dig into the data sheet and see how SS pin is being toggled, at what frequency and all. So tell me one thing. In what SPI mode is the WM8731 chip being operated here .Is it a slave or a master? Because the Arduino library only works in master mode in which the WM8731 should be slave and receiving clock signals from the Arduino but if wm8731 is in master mode then it should be providing the clock signals to arduino (like the clock input pin T1 in Atmega328 or T5 in the Arduino mega) but the arduino cannot be in slave mode as the SPI library wont work for that. So can I put the WM8731 in slave mode. Please tell me what I have to set in the I2C to configure it initially in slave mode.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

PreviousNext

Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron