[SOLVED]Audio codec shield with Arduino Due

Re: Audio codec shield with Arduino Due

Postby guest » Fri Jul 31, 2015 11:09 am

you are getting closer. the scope shots show the problem - the SS pin is toggled too early. you are correct that the SS should be the LRC and the SCK the BCK in the WM8731 datasheet pictures. try to replicate what i did for the maple, and then check the scope again and see what happens. basically, do the following:

set SS high
transfer first data packet on SPI
set SS low
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Fri Jul 31, 2015 9:42 pm

First data packet means a byte or a bit. Because I am thinking that it is first bit, I already tried to make it low after the first byte but I did not get any data.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Fri Jul 31, 2015 10:25 pm

Here is the code for SPI transfer
Code: Select all
void SPIWrite(uint8_t val)
{
    //Wait for previous transfer to complete
    while ((SPI0->SPI_SR & SPI_SR_TXEMPTY) == 0);
     
    //load the Transmit Data Register with the value to transmit
    SPI0->SPI_TDR = val;
     
    //Wait for data to be transferred to serializer
    while ((SPI0->SPI_SR & SPI_SR_TDRE) == 0);
}

How shall I sync it up? I will look at your library and decide that.I will post the updated ISR handler code later.

The following is Maple code.I am not able to understand this.
Code: Select all
static inline void AudioCodec_data(int16* _lin, int16* _rin, int16 _lout, int16 _rout) {

  GPIOA_BASE->BSRR = 0x00000010; // set ss high
  SPI1_BASE->DR = _lout; // send out left data
  asm volatile ("nop"); // delay for appropriate timing
  asm volatile ("nop");
  asm volatile ("nop");
  asm volatile ("nop");
  asm volatile ("nop");
  asm volatile ("nop");
  asm volatile ("nop");
  asm volatile ("nop");
  asm volatile ("nop");
  GPIOA_BASE->BSRR = 0x00100000; // set ss low
  while (!(SPI1_BASE->SR & (1 << SPI_SR_TXE_BIT))) { // wait for data to be sent
  }
  SPI1_BASE->DR = _rout; // send out right data
  while (!(SPI1_BASE->SR & (1 << SPI_SR_RXNE_BIT))) { // wait for data to arrive
  }
  *_lin = SPI1_BASE->DR; // recieve left data
  while (!(SPI1_BASE->SR & (1 << SPI_SR_RXNE_BIT))) { // wait for data to arrive
  }
  *_rin = SPI1_BASE->DR; // recieve right data
}
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sat Aug 01, 2015 1:29 am

I wrote the following code for the SPI transfers in the ISR. Is this right?
Code: Select all
void TC8_Handler()
{
  ledon1 = !(ledon1);
  digitalWrite(13, ledon1);
  //delayMicroseconds(3);
 
  while ((SPI0->SPI_SR & SPI_SR_TXEMPTY) == 0);
  digitalWriteDirect(12, HIGH);
  SPI0->SPI_TDR = lout;
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
 
 
 while((SPI0->SPI_SR & SPI_SR_TDRE)==0)
 {;}
  digitalWriteDirect(12, LOW);
 SPI0->SPI_TDR = rout;
 while((SPI0->SPI_SR & SPI_SR_TDRE)==0)
 {;}
 while((SPI0->SPI_SR & SPI_SR_RDRF) == 0)
 {;}
 lin = SPI0->SPI_RDR;
  while((SPI0->SPI_SR & SPI_SR_RDRF) == 0)
 {;}
 rin = SPI0->SPI_RDR;
 
  //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(temp), SPI_CONTINUE);
  //temp_spi[3] = SPI.transfer(10, lowByte(temp), SPI_LAST);
  //left_in - (temp_spi[0]<<8)|temp_spi[1];
  //right_in = (temp_spi[2]<<8)|temp_spi[3];
  delayMicroseconds(22);
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  status = TC_GetStatus(TC2, TC2_CHANNEL_FOR_TCLK8);
}
Last edited by youthreewire on Sat Aug 01, 2015 3:34 am, edited 1 time in total.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sat Aug 01, 2015 2:52 am

I am getting this graph.As you can see the yellow peak now overlaps with the green peak.Not at the cycle of the rising edge but just at the falling edge. Is this graph right or should I change something more?
IMG_20150801_151815.jpg
IMG_20150801_151815.jpg (197.55 KiB) Viewed 13416 times

"lout" reads as 0 and "lin" reads a constant 917504 .What shall I do now?
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sat Aug 01, 2015 4:05 am

I tried now again and I get these values (it is either of these 3 or 4 values).
serial values.jpg
serial values.jpg (42.5 KiB) Viewed 13416 times
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sat Aug 01, 2015 4:11 am

I am getting some thing on the "lin" and "rin" but it is always a number starting with 91000 and I think it might be because these integer variables in Due are 32 bit but the values read from the codec are 16 bit. Could you please give your opinion on this.
lin and rin.jpg
lin and rin.jpg (70.41 KiB) Viewed 13416 times
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sat Aug 01, 2015 4:19 am

When I am making noise before the mic these values are changing but I now have to see if they can be set to 16 bit. I did lout=lin and rout=rin but I do not get an echo back. Now I have declared these integers as short int which means 16 bit but the ISR gets stuck if I used short int. I do not know how to get an echo now. Could you test my code if you have a Due?
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sat Aug 01, 2015 4:58 am

WIERD thing, When I connect the oscilloscope probes to tap the SCK and SS pin I get the mic values responding to sound and additionally if I change the sensitivity (by pressing a button) on the probe I also get an echo back on one of the speakers of the headphone.Now when I remove the probes I just constant values 917504. What could be the problem?
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Sat Aug 01, 2015 11:22 pm

that oscilloscope shot looks good.

so, if i understand correctly, it works when the scope is connected, but not elsewise? if so, first - congratulations on getting it working, but second, it must be ringing on the lines messing things up. put a 10pF capacitor where you had the scope probe and see if it makes it work.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

PreviousNext

Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest