Page 1 of 5

Audio codec shield with Intel Edison

PostPosted: Thu Aug 06, 2015 10:24 am
by youthreewire


After developing a library successfully for the Arduino Due I am planning to extend the same to Intel Edison. So what functionality do we need? Edison does I2C, it can mimic timers and interrupts though actually it does not have them. I think I might have to see how to use an external clock signal to generate interrupts on the edison.

Apart from the external clock interrupt I dont see what problem there could be.Please pour in your suggestions.I will also start a thread in the edison forums.


Re: Audio codec shield with Intel Edison

PostPosted: Fri Aug 07, 2015 10:35 pm
by youthreewire
So what is the relation between the CLKOUT signal at 11 mhz from the the codec and the ISR at 44 khz. I mean how should the CLKOUT signal and SS pin wave together look like in the oscilloscope?

Re: Audio codec shield with Intel Edison

PostPosted: Sat Aug 08, 2015 11:32 am
by guest
i dont know anything about the edison, but i have a friend i can ask.

as for the clk_out, that should really be at 5.5MHz. its ok if its 11MHz, but the CK/2 bit should be set in the setup registers. the SS output and the clock signal should be synchronized with each other. ie, if you look at them on the scope, they should not move with respect to each other.

Re: Audio codec shield with Intel Edison

PostPosted: Mon Aug 10, 2015 5:33 am
by youthreewire
So when I am using SCL and SDA in I2C what among them is output or input. I think SCL might be output and SDA an input pin. Because in doing I2C communication I need to set the output and input pins. I will first try I2C with BYPASS enable and see if first I2C is working. Then I will code for ISR and timers and then SPI.

Re: Audio codec shield with Intel Edison

PostPosted: Mon Aug 10, 2015 5:45 am
by youthreewire
Just tested I2C, it is working and configuring the codec as needed.I will move onto interrupts,SS and SPI.

Re: Audio codec shield with Intel Edison

PostPosted: Mon Aug 10, 2015 11:20 pm
by youthreewire
The question you might want to ask your friend is how do you track at external interrupt signal at 11Mhz/256 (for 44 Khz) and this timing should drive the ISR.

Re: Audio codec shield with Intel Edison

PostPosted: Tue Aug 11, 2015 4:10 am
by youthreewire
You told me in the past that the first pulse of SS should be aligned with the falling edge of SPI Clock. I understood that but now I want to know how should the SS pin wave be aligned to the 11Mhz or 5.5Mhz CLKOUT signal from the codec? Since I am not able to track the CLKOUT in edison I will try to read the moment when it is high and start the timer with respect to the rising edge of the CLKOUT signal. If align them this way at the beginning will it remain aligned for the rest of the time or should we see the RISING edge every time?Please let me know.

Re: Audio codec shield with Intel Edison

PostPosted: Tue Aug 11, 2015 7:03 am
by youthreewire
My code for Edison. I2C works and configures the codec right but SPI is still work in progress. Will debug this tomorrow using the scope
Code: Select all
#include <TimerOne.h>
#include "SPI.h"
#include <Wire.h>
#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
int myi=0;
bool ledon;
int temp_spi[4];
volatile unsigned int temp =0;

void AudioCodec_init() {

  // 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.write(0x0c); // power reduction register
  Wire.write((uint8_t)0x00); // turn everything on
  temp_wire1 = Wire.endTransmission();

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


  Wire.write((uint8_t)0x00); // left in setup register

  Wire.write(0x02); // right in setup register

  Wire.write(0x04); // left headphone out register

  Wire.write(0x06); // right headphone out register

  Wire.write(0x0a); // digital audio path configuration

  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.write(0x10); // clock configuration
#if SAMPLE_RATE == 88
#elif SAMPLE_RATE == 44
#elif SAMPLE_RATE == 22
#elif SAMPLE_RATE == 8
#elif SAMPLE_RATE == 2

  Wire.write(0x12); // codec enable


void setup()
  // Initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards
  //system("echo 40 > /sys/class/gpio/export");
   system("echo 128 > /sys/class/gpio/export"); //pin 2
  system("echo 42 > /sys/class/gpio/export");//pin  13
  system("echo in > sys/class/gpio/gpio128/direction");

   SPI.begin();  // Begin SPI hardware
  Timer1.initialize(125); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
  Timer1.attachInterrupt(timerIsr,CHANGE ); // attach the service routine here
  //attachInterrupt(2, pinChange, CHANGE);
void loop()
   Timer1.attachInterrupt(timerIsr,CHANGE );

   Serial.print(" ");
   Serial.print(" ");
   Serial.print(" ");

void timerIsr()
    // Toggle LED

   temp = random(65535);
        temp_spi[0] = SPI.transfer(highByte(temp));
        temp_spi[1] = SPI.transfer(lowByte(temp));
        temp_spi[2] = SPI.transfer(highByte(temp));
        temp_spi[3] = SPI.transfer(lowByte(temp));

Re: Audio codec shield with Intel Edison

PostPosted: Tue Aug 11, 2015 12:09 pm
by guest
i asked my friend about the edison, and he said it doesnt have any hardware timers that are usable. im not sure how interrupts even work on it. you could put an external counter chip on, but it ultimately may not work. the codecshield is set to work in slave mode, which is not very conducive to most larger platforms. with the edison you can just put a usb sound card on it.

with the master clock and SS signals, i dont think it matters whether its aligned to rising or falling edge, just as long as its consistent.

Re: Audio codec shield with Intel Edison

PostPosted: Tue Aug 11, 2015 9:31 pm
by youthreewire
Software emulation of timers and interrupts is there on edison.I am able to get an 8khz interrupt on the edison.Here is the scope shot:
IMG_20150811_144937.jpg (115.75 KiB) Viewed 17486 times