Have the shield working with Mega - library attached

Have the shield working with Mega - library attached

Postby scott2 » Tue Dec 04, 2012 5:36 pm

I finally got it using a little DAQ/digital signal analyzer

It's a bit of timing voodoo - basically came down to making the SPI calls after the I2C calls for the chip config. An updated library+examples for the Mega is attached below.

The init function now looks like:
Code: Select all
void AudioCodecMega_init(){
  // setup i2c pins and configure codec
  // the new Wire library has trouble with 0x00, so (uint8_t) is added
  Wire.begin();
  Wire.beginTransmission(0x1a);
  Wire.write(0x0c); // power reduction register
  Wire.write((uint8_t)0x00); // turn everything on
  Wire.endTransmission();
 
...

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

  // setup spi peripheral
  pinMode (53, OUTPUT);
  digitalWrite(53, LOW); // set ss pin to output low
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setDataMode(SPI_MODE0);

...
}

Attachments
AudioCodecMega.zip
Codec Library updated for Mega
(26.49 KiB) Downloaded 1452 times
scott2
 
Posts: 15
Joined: Thu Sep 27, 2012 5:48 pm

Re: Have the shield working with Mega - library attached

Postby guest » Wed Dec 05, 2012 5:19 pm

this is awesome, thanks for digging into it. ill give the library a read over.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Have the shield working with Mega - library attached

Postby scott2 » Wed Dec 05, 2012 5:25 pm

np!

It's exactly the same code, except:
- just moved the location of the SPI init calls
- Updated to timer 5 being driven by the shield instead of 1 I think it was before. Updated the example code to look @ the T5 interrupt vector instead.


You may want to update the docs with the new pin mappings as discussed in other forum threads. Didn't write anything about that in there.
scott2
 
Posts: 15
Joined: Thu Sep 27, 2012 5:48 pm

Re: Have the shield working with Mega - library attached

Postby guest » Wed Dec 05, 2012 6:12 pm

cool, will do. i will also add in the clobber list at the end of the asm calls. its something i forgot to do on the first library i wrote, which is probably the one you ended up grabbing. basically, it tells the compiler which registers the assembly calls are using, so that they can be handled correctly in interrupts and such.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Have the shield working with Mega - library attached

Postby Brownian Lotion » Fri Aug 08, 2014 10:07 pm

Thanks for making the Mega library!

I am a newbie to this platform and just trying to get it working at this stage.

Unfortunately, there's no sound at present. Can I confirm that the pin changes are these below?

Code: Select all
UNO MEGA FUNCTION
--- ---- --------
A4  D20  I2C (SDA)
A5  D21  I2C (SCL)
D10 D53  SPI (SS)
D11 D51  SPI (MOSI)
D12 D50  SPI (MISO)
D13 D52  SPI (SCK)
D5  D47  T1 -> T5


The UNO pins A4 and A5 weren't listed in the other Mega thread - instead they were noted as A6 and A7.
Brownian Lotion
 
Posts: 6
Joined: Fri Aug 08, 2014 7:15 am

Re: Have the shield working with Mega - library attached

Postby guest » Sat Aug 09, 2014 6:42 am

those are all the correct UNO pins. how are you testing it?
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Have the shield working with Mega - library attached

Postby Brownian Lotion » Sun Aug 10, 2014 12:54 am

My testing procedure was to load up the mega library version of the sine generator example and listen to the output through headphones. There is currently no output.

I will try with another non-mega arduino tonight to test the codec board.

EDIT: Tested with a Diecimila board. The non-mega sine sketch works perfectly, so it's not my codec shield.
Brownian Lotion
 
Posts: 6
Joined: Fri Aug 08, 2014 7:15 am

Re: Have the shield working with Mega - library attached

Postby guest » Sun Aug 10, 2014 7:42 am

so, there are 2 communication formats involved, i2c and spi. im guessing the i2c might not be working. you can test this as follows:

Code: Select all
// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 44 // 44.1Khz
#define ADCS 0 // no ADCs are being used
#define BYPASS 1 // turn on bypass

// include necessary libraries
#include <Wire.h>
#include <SPI.h>
#include <AudioCodecMega.h>

// create data variables for audio transfer
int left_in = 0x0000;
int left_out = 0x0000;
int right_in = 0x0000;
int right_out = 0x0000;

void setup() {
  AudioCodecMega_init(); // setup codec registers
  // call this last if setting up other parts
}

void loop() {
  while (1); // reduces clock jitter
}

// timer1 interrupt routine - all data processed here
ISR(TIMER5_COMPA_vect, ISR_NAKED) { // dont store any registers
  reti(); // do nothing
}


this turns on the bypass, so whatever goes into the input, comes out the output. run this code, and put a signal at the input, and listen for it at the output. if you can hear the signal at the output, then the I2C is working.

also, it doesnt look like the clobber list ever got put into the OPs library. this may be causing the problem, although not likely.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: Have the shield working with Mega - library attached

Postby Brownian Lotion » Mon Aug 11, 2014 5:31 am

That works!

So I2C is working?
Brownian Lotion
 
Posts: 6
Joined: Fri Aug 08, 2014 7:15 am

Re: Have the shield working with Mega - library attached

Postby guest » Mon Aug 11, 2014 5:52 am

yes, I2C is working, which is good news. so lets try a simple sketch to test the SPI:

Code: Select all
    // setup codec parameters
    // must be done before #includes
    // see readme file in libraries folder for explanations
    #define SAMPLE_RATE 44 // 44.1Khz
    #define ADCS 0 // no ADCs are being used

    // include necessary libraries
    #include <Wire.h>
    #include <SPI.h>
    #include <AudioCodecMega.h>

    // create data variables for audio transfer
    int left_in = 0x0000;
    int left_out = 0x0000;
    int right_in = 0x0000;
    int right_out = 0x0000;

    void setup() {
      AudioCodecMega_init(); // setup codec registers
      // call this last if setting up other parts
    }

    void loop() {
      while (1); // reduces clock jitter
    }

    // timer1 interrupt routine - all data processed here
    ISR(TIMER5_COMPA_vect) { // NAKED turned off, so registers are stored
      AudioCodecMega_data(&left_in, &right_in, left_out, right_out);
      left_out = left_in;
      right_out = right_in;
      //reti(); // dont need this without NAKED
    }


this should send the input to the output, but without the bypass. if the SPI does not work, there are 2 likely causes: 1 something wrong with the code that is messing up the interrupts. 2 something is wrong with the wiring. the SPI moves at a very fast rate, so long wires could cause problems. also, double check that you have the right pins going to the right holes.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Next

Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron