Page 4 of 12

Re: Audio codec shield with Arduino Due

PostPosted: Fri Jun 19, 2015 10:21 pm
by guest
the codecshield needs to be operated in slave mode, so it should work fine with the SPI on that account. note that your SS pin is always high, and only goes low during data transfer. if you look at the datasheet for the wm8731, this is the opposite of what you want. you might be better of using a different pin than the ss pin, and just generate your own ss signal in the interrupt.

Re: Audio codec shield with Arduino Due

PostPosted: Sat Jun 20, 2015 12:55 am
by youthreewire
The codec shield is the slave? But then what about the clock signal on pin T1 (on the atmega328 like arduinos).I think T1 is receiving the clock input from the codec shield. When I disconnected the pin it is not working.I think PIN T1 goes with the timer and accepts input from the WM8731 for clock. Please check the schematic and function of T1 pin in your code. You are using Timer 1 in your code and magically this implied that you were using the T1 pin and hardwiring it to clkout on the codec shield. I exactly did not understand the function of T1 pin.Could you explain more?

It is clear that the T1 pin is for external clock input timer interrupt. The data sheet of WM8731 says that if WM8731 is master it will send the clock signal.So one more doubt is is this clock signal on CLKOUT is what they are referring to or is it SCK clock for SPI?

Re: Audio codec shield with Arduino Due

PostPosted: Sat Jun 20, 2015 10:49 am
by guest
there are 3 clock signals on the codecshield:

1. I2C clock
2. SPI clock
3. codec master clock

the microcontroller T1 recieves the codec master clock, which should then fire an interrupt to drive the SPI. so SPI on the codec is in slave mode, whereas the codec master clock is in master mode.

Re: Audio codec shield with Arduino Due

PostPosted: Sat Jun 20, 2015 10:57 pm
by youthreewire
What is the value of CLKOUT. So is it absolutely necessary to get the timer interrupt from CLKOUT? And what is the frequency of master clock.I went through the data sheet but could not find it.

Re: Audio codec shield with Arduino Due

PostPosted: Sun Jun 21, 2015 3:03 am
by youthreewire
I found some information about the Due timers here:
https://github.com/ivanseidel/DueTimer

Here they mention about connecting an external clock but TCLK0 but also mentioned about I/O Lines TIOA0 ,TIOB0. i am confused here.
https://github.com/ivanseidel/DueTimer/blob/master/TimerCounter.md

Re: Audio codec shield with Arduino Due

PostPosted: Sun Jun 21, 2015 1:37 pm
by guest
that code does not allow for external clocks as one of its options. i found this arduino forum link that might be of some help:
http://forum.arduino.cc/index.php?topic=311872.0

it doesnt look like there is a standard library for doing this yet. the due is quite new, and there isnt a lot of support for it yet.

Re: Audio codec shield with Arduino Due

PostPosted: Sun Jun 21, 2015 10:04 pm
by youthreewire
I tried the sketch in the thread but I get no update in the print statement. Everything reads zero. The sketch does not detect the CLKOUT signal on pin30.

I even ran this code here:
http://www.at91.com/discussions/viewtopic.php/f,24/t,23968/p,45148.html
But external IRQs still read 0.

The CLKOUT signal is a 11Mhz signal. But in both the example codes above the input signal is either a 0.5Hz signal or a 3 hz signal on pin30.

Re: Audio codec shield with Arduino Due

PostPosted: Sun Jun 21, 2015 11:52 pm
by guest
did you follow this instruction in the original thread:
Remove TC_CMR_BURST_XC2 from TC2UsingExternalClock.ino

this was the same problem the other thread mentions as well

Re: Audio codec shield with Arduino Due

PostPosted: Mon Jun 22, 2015 2:02 am
by youthreewire
Yes I did remove that. The CLKOUT signal is a 11Mhz signal. But in both the example codes above the input signal is either a 0.5Hz signal or a 3 hz signal on pin30. I also gave it a signal from pin13 (LED) blinking every second but still I get 0.

I wonder how your library worked for the atmega328 based arduinos. Because once we set interrupts on the external clock of 11Mhz hardly any time might be left for the main loop to run.I was still able to send data over serial port from the main loop using your library.

Re: Audio codec shield with Arduino Due

PostPosted: Mon Jun 22, 2015 6:27 am
by youthreewire
Here is the video of my test.
http://youtu.be/CA1SehE_l60

due with connections.jpg

Code: Select all
#define TC2_CHANNEL_FOR_TCLK8 2  /* presumed to correspond to XC2 */

volatile int irqsServiced;
unsigned int status;
int upflag = 0;
bool ledon=0;
int oldmillis=0;
/****************************************************************/

void TC8_Handler()
{
   /* clear interrupt */
   status = TC_GetStatus(TC2, TC2_CHANNEL_FOR_TCLK8);
   irqsServiced++;
}


/****************************************************************/

void setup()
{
   Serial.begin(115200);
        pinMode(13,OUTPUT);
        pinMode(30,INPUT);
   /* "The user must configure the Power Management Controller before any access to the input line information." per 34.4.2 */
   pmc_enable_periph_clk(ID_TC8);
   /* "Using the PIO Controller requires the NVIC to be programmed first." per 34.4.3 */
   NVIC_EnableIRQ(TC8_IRQn);
   /* external clock is an input */
   PIO_Configure(PIOD, PIO_INPUT, PIO_PD9, 0);
   /* TCLK8 is the "B" peripheral */                       
   PIO_SetPeripheral(PIOD, PIO_PERIPH_B, PIO_ABSR_P9);

   /* use internal clock */
   TC_Configure(TC2, TC2_CHANNEL_FOR_TCLK8,
             (TC_CMR_TCCLKS_XC2 |
              TC_CMR_EEVTEDG_RISING |
              TC_CMR_EEVT_XC2 |
              TC_CMR_ENETRG |
              TC_CMR_WAVSEL_UP_RC |
              TC_CMR_WAVE));
   /* load counter register */
   TC_SetRC(TC2, TC2_CHANNEL_FOR_TCLK8, 13);
   /* start the timer */
   TC_Start(TC2, TC2_CHANNEL_FOR_TCLK8);
   /* enable the timer-specific interrupts */
   REG_TC2_IER2 = TC_IER_CPCS;
}


/****************************************************************/

void loop()
{
   //delay(1000);
        if(upflag==0)
        {
        oldmillis = millis();
        upflag=1;
        }
        if((millis()-oldmillis)>=200)
        {
        ledon=!ledon;
        digitalWrite(13,ledon);
        upflag=0;
        }
       
   printf("irqsServiced: %d, status: %08x, CV2: %d\n", irqsServiced, status, REG_TC2_CV2);
   if (Serial.available() > 0)
   {
      char choice = Serial.read();
      if (choice == 'z')
      {
         REG_TC2_BCR = TC_BCR_SYNC;
      }
   }
}