[SOLVED]Audio codec shield with Arduino Due

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Aug 02, 2015 6:30 am

It worked for quite some time when I connected the probe but now it is not working either if I connect to scope or not. So how shall I debug this?I am getting constant values like 917504 and these values stop coming from the serial port after some time. The serial port gets stuck but the ISR keeps running (as I am blinking an led on pin13). Please let me know.

But there is some other problem. Right now I am getting only 16 bits.I might have to add some more lines in the SPI to get two 16 bits (i.e 32 bits in total for two 16 bit values like lin and rin). My main loop stops spitting out serial port values but he ISR still runs.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Sun Aug 02, 2015 9:20 am

can you post your SPI code?

i wouldnt use the serial port at all at this point. it just makes it more dfficult. just do a loopback test to see if it works (rout = rin, etc). also, it stops working if the clock gets out of sync. so make sure that the timer/counter block is working properly. its possible its off by just a bit, goes in and out of sync.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Aug 02, 2015 8:04 pm

I already posted my SPI code. Anyways it is here again
Code: Select all
void TC8_Handler()
{
  ledon1 = !(ledon1);
  digitalWrite(13, ledon1);
 
  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;
 
  delayMicroseconds(22);
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  status = TC_GetStatus(TC2, TC2_CHANNEL_FOR_TCLK8);
}
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Aug 02, 2015 10:56 pm

I am not able to get the timing right. So if you can try the code with an Arduino Due I would be very thankful. Here is my code but you will need an oscilloscope.
Code: Select all
#include<SPI.h>
#include<Wire.h>
#include "stdint.h"
#define TC2_CHANNEL_FOR_TCLK8 2  /* presumed to correspond to XC2 */
#define LINVOL 23
#define RINVOL 23
#define LHPVOL 100
#define RHPVOL 100
#define ADCHPD 0
#define SIDEATT 0
#define SIDETONE 0
#define DACSEL 1
#define BYPASS 0
#define INSEL 0
#define MUTEMIC 1
#define MICBOOST 0
#define SAMPLE_RATE 8

volatile boolean l;
int cnt = 0, startflag = 0;
unsigned int temp = 0, temp1 = 0;
volatile int temp_spi[4];
int m1[301], m2[301];
//TC1 ch 0
int left_out, right_out;
volatile int lin,rin,lout,rout;
volatile int modlin,modrin;

enum Phase
{
  TC2_INTERNAL,
  PIOD_EXTERNAL,
  TC2_EXTERNAL,
  DONE
};

/* enum Phase
 {
    TC2_EXTERNAL,
    TC2_EXTERNAL,
    TC2_EXTERNAL,
    DONE
 };*/

Phase phase;
volatile int pioIRQsServiced;
volatile int tc2IRQsServiced[3];
unsigned int status;
int upflag = 0;
volatile bool ledon, ledon1 = 0;
int oldmillis = 0;
volatile int left_in = 30000;
volatile int right_in = 30000;
volatile int myi = 0;
#define _BV(bit) (0x1u << bit)

void InitPIO()
{
    //Because we are using PORTB.PIN25 in peripheral B mode
    //  we need to enable the clock for that line.
    PMC->PMC_PCER0 |= _BV(ID_PIOA);
     
    //configure for input
    PIOA->PIO_PDR |= PIO_PA25;
    PIOA->PIO_ODR |= PIO_PA25;       //Input
     
    PIOA->PIO_PDR |= PIO_PA26;       //MOSI
    PIOA->PIO_OER |= PIO_PA26;       //MOSI  Output
    PIOA->PIO_ABSR &= ~PIO_PA26; //Peripheral A
     
    PIOA->PIO_PDR |= PIO_PA27;       //SPCK
    PIOA->PIO_OER |= PIO_PA27;       //SPCK  Output
    PIOA->PIO_ABSR &= ~PIO_PA27; //Peripheral A
     
    PIOA->PIO_PDR |= PIO_PA28;       //NPCS0
    PIOA->PIO_OER |= PIO_PA28;       //NPCS0 Output
    PIOA->PIO_ABSR &= ~PIO_PA28; //Peripheral A 
    PIOA->PIO_PUER |= PIO_PA28;      //pull-up
}

void InitSPI()
{
    //Enable clock for the SPI0 peripheral
    PMC->PMC_PCER0 |= _BV(ID_SPI0);
    //Disable the SPI0 peripheral so we can configure it.
    SPI0->SPI_CR = SPI_CR_SPIDIS;
    //Set as Master, Fixed Peripheral Select, Mode Fault Detection disabled and
    //  Peripheral Chip Select is PCS = xxx0 NPCS[3:0] = 1110
    SPI0->SPI_MR = SPI_MR_MSTR | SPI_MR_MODFDIS | 0x000e0000;
     
    //SPCK baudrate = MCK / SCBR = 84MHz / 128 = 656250Hz
    SPI0->SPI_CSR[0] |= 0x00008000;     
     
    //Enable the SPI0 unit
    SPI0->SPI_CR = SPI_CR_SPIEN;
}

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);
}
/****************************************************************/

void PIOD_Handler(void)
{
  /* clear interrupt */
  status = REG_PIOD_ISR;
  pioIRQsServiced++;
}


/****************************************************************/
inline void digitalWriteDirect(int pin, boolean val) {
  if (val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
  else    g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}

inline int digitalReadDirect(int pin) {
  return !!(g_APinDescription[pin].pPort -> PIO_PDSR & g_APinDescription[pin].ulPin);
}

void TC8_Handler()
{
 ledon1 = !(ledon1);
  digitalWrite(13, ledon1);
 
  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);
  while ((SPI0->SPI_SR & SPI_SR_TXEMPTY) == 0);
 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;
  delayMicroseconds(60);
  /*__asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");
  __asm__("nop");*/
  //status = TC_GetStatus(TC2, TC2_CHANNEL_FOR_TCLK8);



}


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

void SetupPIOD(void)
{
  int result;

  /* power on PIO ("Parallel Input/Output Controller") controller D */
  pmc_enable_periph_clk(ID_PIOD);
  /* enable interrupts for PIOD */
  NVIC_EnableIRQ(PIOD_IRQn);
  /* configure PD9 as general-purpose IO pin as opposed to the TCLK8 peripheral */
  result = PIO_Configure(PIOD, PIO_INPUT, PIO_PD9, PIO_IT_RISE_EDGE);
  printf("%d <- PIO_Configure\n", result);
  /* ensure we're interrupting on the rising edge of the external clock */
  REG_PIOD_AIMER = PIO_PD9;
  REG_PIOD_ESR = PIO_PD9;
  REG_PIOD_REHLSR = PIO_PD9;
  /* enable interrupts */
  REG_PIOD_IER = PIO_PD9;
}


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

void TakeDownPIOD(void)
{
  TC_Stop(TC2, TC2_CHANNEL_FOR_TCLK8);
  TC_SetRC(TC2, TC2_CHANNEL_FOR_TCLK8, 0);
  REG_PIOD_IDR = PIO_PD9;
  NVIC_DisableIRQ(TC8_IRQn);
  pmc_disable_periph_clk(ID_PIOD);
}


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

void SetupTC2(bool useInternalClock)
{
  int result;

  /* "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);
  result = PIO_Configure(PIOD, PIO_PERIPH_B, PIO_ABSR_P9, PIO_DEFAULT);
  //printf("%d <- PIO_Configure\n", result);
 /* if (useInternalClock)
  {
    TC_Configure(TC2,
                 TC2_CHANNEL_FOR_TCLK8,
                 TC_CMR_TCCLKS_TIMER_CLOCK4 | TC_CMR_WAVSEL_UP_RC | TC_CMR_WAVE);
  }
  else*/
  {
    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));
  }
  //5714285
  uint32_t rc = (5714285 / 714); //128 because we selected TIMER_CLOCK4 above
  //TC_SetRA(tc, channel, rc/2); //50% high, 50% low
  //TC_SetRC(tc, channel, rc);
  //TC_Start(tc, channel);

  TC_SetRA(TC2, TC2_CHANNEL_FOR_TCLK8, rc/2);
  TC_SetRC(TC2, TC2_CHANNEL_FOR_TCLK8, rc);
  /* start the timer */
  TC_Start(TC2, TC2_CHANNEL_FOR_TCLK8);
  /* enable the timer-specific interrupts */
  REG_TC2_IER2 = TC_IER_CPCS | TC_IER_ETRGS;
  TC2->TC_CHANNEL[TC2_CHANNEL_FOR_TCLK8].TC_IER = TC_IER_CPCS;
  TC2->TC_CHANNEL[TC2_CHANNEL_FOR_TCLK8].TC_IDR = ~TC_IER_CPCS;
  NVIC_EnableIRQ(TC8_IRQn);
}


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

void TakeDownTC2(void)
{
  TC_Stop(TC2, TC2_CHANNEL_FOR_TCLK8);
  TC_SetRC(TC2, TC2_CHANNEL_FOR_TCLK8, 0);
  REG_TC2_IDR2 = TC_IER_CPCS | TC_IER_ETRGS;
  NVIC_DisableIRQ(TC8_IRQn);
  pmc_disable_periph_clk(ID_TC8);
}

/* Clock settings (96MHz) */
#define SYS_BOARD_OSCOUNT   (CKGR_MOR_MOSCXTST(0x8UL))
#define SYS_BOARD_PLLAR     (CKGR_PLLAR_ONE \
                             | CKGR_PLLAR_MULA(0xfUL) \
                             | CKGR_PLLAR_PLLACOUNT(0x3fUL) \
                             | CKGR_PLLAR_DIVA(0x1UL))
#define SYS_BOARD_MCKR      (PMC_MCKR_PRES_CLK_2 | PMC_MCKR_CSS_PLLA_CLK)

/* Clock Definitions */
#define SYS_UTMIPLL             (480000000UL)   /* UTMI PLL frequency */

#define SYS_CKGR_MOR_KEY_VALUE  CKGR_MOR_KEY(0x37UL) /* Key to unlock MOR register */

/* FIXME: should be generated by sock */
uint32_t SystemCoreClock = CHIP_FREQ_MAINCK_RC_4MHZ;

void SystemInit(void)
{
  /* Set FWS according to SYS_BOARD_MCKR configuration */
  EFC0->EEFC_FMR = EEFC_FMR_FWS(4);
  EFC1->EEFC_FMR = EEFC_FMR_FWS(4);

  /* Initialize main oscillator */
  if (!(PMC->CKGR_MOR & CKGR_MOR_MOSCSEL)) {
    PMC->CKGR_MOR = SYS_CKGR_MOR_KEY_VALUE | SYS_BOARD_OSCOUNT |
                    CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN;
    while (!(PMC->PMC_SR & PMC_SR_MOSCXTS)) {
    }
  }

  /* Switch to 3-20MHz Xtal oscillator */
  PMC->CKGR_MOR = SYS_CKGR_MOR_KEY_VALUE | SYS_BOARD_OSCOUNT |
                  CKGR_MOR_MOSCRCEN | CKGR_MOR_MOSCXTEN | CKGR_MOR_MOSCSEL;

  while (!(PMC->PMC_SR & PMC_SR_MOSCSELS)) {
  }
  PMC->PMC_MCKR = (PMC->PMC_MCKR & ~(uint32_t)PMC_MCKR_CSS_Msk) |
                  PMC_MCKR_CSS_MAIN_CLK;
  while (!(PMC->PMC_SR & PMC_SR_MCKRDY)) {
  }

  /* Initialize PLLA */
  PMC->CKGR_PLLAR = SYS_BOARD_PLLAR;
  while (!(PMC->PMC_SR & PMC_SR_LOCKA)) {
  }

  /* Switch to main clock */
  PMC->PMC_MCKR = (SYS_BOARD_MCKR & ~PMC_MCKR_CSS_Msk) | PMC_MCKR_CSS_MAIN_CLK;
  while (!(PMC->PMC_SR & PMC_SR_MCKRDY)) {
  }

  /* Switch to PLLA */
  PMC->PMC_MCKR = SYS_BOARD_MCKR;
  while (!(PMC->PMC_SR & PMC_SR_MCKRDY)) {
  }

  SystemCoreClock = CHIP_FREQ_CPU_MAX;
}

void SystemCoreClockUpdate(void)
{
  /* Determine clock frequency according to clock register values */
  switch (PMC->PMC_MCKR & PMC_MCKR_CSS_Msk) {
    case PMC_MCKR_CSS_SLOW_CLK: /* Slow clock */
      if (SUPC->SUPC_SR & SUPC_SR_OSCSEL) {
        SystemCoreClock = CHIP_FREQ_XTAL_32K;
      } else {
        SystemCoreClock = CHIP_FREQ_SLCK_RC;
      }
      break;
    case PMC_MCKR_CSS_MAIN_CLK: /* Main clock */
      if (PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) {
        SystemCoreClock = CHIP_FREQ_XTAL_12M;
      } else {
        SystemCoreClock = CHIP_FREQ_MAINCK_RC_4MHZ;

        switch (PMC->CKGR_MOR & CKGR_MOR_MOSCRCF_Msk) {
          case CKGR_MOR_MOSCRCF_4_MHz:
            break;
          case CKGR_MOR_MOSCRCF_8_MHz:
            SystemCoreClock *= 2U;
            break;
          case CKGR_MOR_MOSCRCF_12_MHz:
            SystemCoreClock *= 3U;
            break;
          default:
            break;
        }
      }
      break;
    case PMC_MCKR_CSS_PLLA_CLK: /* PLLA clock */
    case PMC_MCKR_CSS_UPLL_CLK: /* UPLL clock */
      if (PMC->CKGR_MOR & CKGR_MOR_MOSCSEL) {
        SystemCoreClock = CHIP_FREQ_XTAL_12M;
      } else {
        SystemCoreClock = CHIP_FREQ_MAINCK_RC_4MHZ;

        switch (PMC->CKGR_MOR & CKGR_MOR_MOSCRCF_Msk) {
          case CKGR_MOR_MOSCRCF_4_MHz:
            break;
          case CKGR_MOR_MOSCRCF_8_MHz:
            SystemCoreClock *= 2U;
            break;
          case CKGR_MOR_MOSCRCF_12_MHz:
            SystemCoreClock *= 3U;
            break;
          default:
            break;
        }
      }
      if ((PMC->PMC_MCKR & PMC_MCKR_CSS_Msk) == PMC_MCKR_CSS_PLLA_CLK) {
        SystemCoreClock *= ((((PMC->CKGR_PLLAR) & CKGR_PLLAR_MULA_Msk) >>
                             CKGR_PLLAR_MULA_Pos) + 1U);
        SystemCoreClock /= ((((PMC->CKGR_PLLAR) & CKGR_PLLAR_DIVA_Msk) >>
                             CKGR_PLLAR_DIVA_Pos));
      } else {
        SystemCoreClock = SYS_UTMIPLL / 2U;
      }
      break;
  }

  if ((PMC->PMC_MCKR & PMC_MCKR_PRES_Msk) == PMC_MCKR_PRES_CLK_3) {
    SystemCoreClock /= 3U;
  } else {
    SystemCoreClock >>= ((PMC->PMC_MCKR & PMC_MCKR_PRES_Msk) >>
                         PMC_MCKR_PRES_Pos);
  }
}

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(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];
  /*Serial.println("Hello");
  Serial.println(temp_spi[0]);
  Serial.println(temp_spi[1]);
  Serial.println(temp_spi[2]);
  Serial.println(temp_spi[3]);*/
}

void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
  pmc_set_writeprotect(false);
  pmc_enable_periph_clk((uint32_t)irq);
  TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4);
  uint32_t rc = VARIANT_MCK / 128 / frequency; //128 because we selected TIMER_CLOCK4 above
  TC_SetRA(tc, channel, rc / 2); //50% high, 50% low
  TC_SetRC(tc, channel, rc);
  TC_Start(tc, channel);
  tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPCS;
  tc->TC_CHANNEL[channel].TC_IDR = ~TC_IER_CPCS;
  NVIC_EnableIRQ(irq);
}

void AudioCodec_init() {
  randomSeed(analogRead(0));
  SPI.begin(10);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(10, 11); // select to ss pin 10, 4 MHz// favourable values 11,21,84
  SPI.setDataMode(10, SPI_MODE0);

  // setup i2c pins and configure codec
  // the new Wire library has trouble with 0x00, so (uint8_t) is added
  // To change the Wire interface speed, go to:
  // <path_from_arduino>\hardware\arduino\sam\libraries\Wire\Wire.h
  // and change the parameters TWI_CLOCK, RECV_TIMEOUT and XMIT_TIMEOUT
  // to the desire frequency.
  int temp_wire1;
  int temp_wire2;

  Wire.begin();
  Wire.beginTransmission(0x1a);
  Wire.write(0x0c); // power reduction register
  Wire.write((uint8_t)0x00); // turn everything on
  temp_wire1 = Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x0e); // digital data format
  Wire.write(0x03); // 16b SPI mode
  temp_wire2 = Wire.endTransmission();

  Serial.println(temp_wire1);
  Serial.println(temp_wire2);

  Wire.beginTransmission(0x1a);
  Wire.write((uint8_t)0x00); // left in setup register
  Wire.write((uint8_t)LINVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x02); // right in setup register
  Wire.write((uint8_t)RINVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x04); // left headphone out register
  Wire.write((uint8_t)LHPVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x06); // right headphone out register
  Wire.write((uint8_t)RHPVOL);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x0a); // digital audio path configuration
  Wire.write((uint8_t)ADCHPD);
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x08); // analog audio pathway configuration
  Wire.write((uint8_t)((SIDEATT << 6) | (SIDETONE << 5) | (DACSEL << 4) | (BYPASS << 3) | (INSEL << 2) | (MUTEMIC << 1) | (MICBOOST << 0)));
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x10); // clock configuration
#if SAMPLE_RATE == 88
  Wire.write(0xbc);
#elif SAMPLE_RATE == 44
  Wire.write(0xa0);
#elif SAMPLE_RATE == 22
  Wire.write(0xe0);
#elif SAMPLE_RATE == 8
  Wire.write(0xac);
#elif SAMPLE_RATE == 2
  Wire.write(0xce);
#endif
  Wire.endTransmission();

  Wire.beginTransmission(0x1a);
  Wire.write(0x12); // codec enable
  Wire.write(0x01);
  Wire.endTransmission();

}
/****************************************************************/

void setup(void)
{
  pinMode(12, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(10, LOW);
  //delay(2000);
  //SPI.begin();
  SystemInit();
  SystemCoreClockUpdate();
  AudioCodec_init();
  //SPI init
  InitPIO();
  InitSPI();
  //startTimer(TC1, 0, TC3_IRQn, 44100);
  //Serial.begin(38400);
  //Serial.println("Hello serial1");
  Serial3.begin(6000000);
  Serial3.println("Ranjan test");
  Serial3.println("start with TC2 internal\n");
  delay(1000);
  SetupTC2(false);
}


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

void loop(void)
{

  //Serial2.println("Rnnjan in loop");
  // temp_spi[0] = SPI.transfer(10,highByte(temp),SPI_CONTINUE);
  phase = TC2_EXTERNAL;
  /*if(startflag==0)
  //if(1)
  {
  //SetupPIOD();
  SetupTC2(false);
  startflag=1;
  }*/

  //Serial.println(phase);
  switch (phase)
  {
    case TC2_INTERNAL:
      if (tc2IRQsServiced[0] > 250000)
      {
        phase = PIOD_EXTERNAL;
        TakeDownTC2();
        printf("PASSED\nswitch to PIOD\n");
        SetupPIOD();
      }
      break;
    case PIOD_EXTERNAL:
      if (pioIRQsServiced > 20)
      {
        phase = TC2_EXTERNAL;
        TakeDownTC2();
        printf("PASSED\nswitch to TC2 external\n");
        SetupTC2(false);
      }
      break;
    case TC2_EXTERNAL:
      SetupTC2(false);
      if (tc2IRQsServiced[1] > 20)
      {
        printf("PASSED!!!\n");
        for ( ; ; );
      }
      break;
    default:
      break;
  }
  //delay(1000);
 /* modlin=lin-917000;
  modrin=rin-917000;
  Serial3.print(modlin);
  Serial3.print(" ");
  Serial3.println(modrin);*/
 
  Serial3.print(lin);
  Serial3.print(" ");
  Serial3.println(rin);
  //Serial3.println(right_in);
  // printf("PIO IRQs: %d, CPCS internal IRQs: %d, CPCS external IRQs: %d, ETRGS external IRQs: %d, status: %08x, CV2: %d\n", pioIRQsServiced, tc2IRQsServiced[0], tc2IRQsServiced[1], tc2IRQsServiced[2], status, REG_TC2_CV2);

}
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Sun Aug 02, 2015 11:55 pm

I could not match the timing for 44khz,22khz but at 8 khz I am able to match the timing. I am getting the scope plots as below but stil I am not getting any output.
IMG_20150803_121533.jpg
IMG_20150803_121533.jpg (174.36 KiB) Viewed 13013 times
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Mon Aug 03, 2015 12:36 am

Now I am getting clean values. The problem was that the clock of the codec was at 11mhz and not at 5.5Mhz. Some how the clock was not getting set to 5.5Mhz although you mentioned earlier that that should be the clock.
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Mon Aug 03, 2015 1:44 am

I change to 16BIT SPI on the due and I am getting nice plots.
IMG_20150803_141020.jpg
IMG_20150803_141020.jpg (112.9 KiB) Viewed 13013 times
youthreewire
 
Posts: 117
Joined: Tue Jun 09, 2015 8:06 pm

Re: Audio codec shield with Arduino Due

Postby guest » Mon Aug 03, 2015 11:04 am

excellent, glad its working. i will look into the 11MHz thing.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby guest » Mon Aug 03, 2015 11:06 am

also, have you tuned your scope probes? there seems to be a lot of ringing in those plots. it could be the circuit, or the probes. there should be a square wave source on the scope that you can connect the probe to, and then turn the small trimmer till the ringing goes away.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Audio codec shield with Arduino Due

Postby youthreewire » Mon Aug 03, 2015 11:05 pm

No I did not tune the probes but it is working great now. Thank you for your support.
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