Go Down

Topic: Error using the AutoAnalogAudio library by TMRh20 (Read 104 times) previous topic - next topic

guzu

So I have been trying to make this library (AutoAnalogAudio - http://tmrh20.github.io/AAAudio/) work with my setup. (Arduino Nano transmitter and Arduino Nano receiver using the Wireless Microphone and Wireless Speaker example sketches from the library.) But so far I did not manage.

In order to be able to upload the code I had to comment out the Arduino Due speciffic lines:

Code: [Select]

    //TcChannel * t = &(TC0->TC_CHANNEL)[0];
    //TcChannel * tt = &(TC0->TC_CHANNEL)[1];

    //Serial.print("Ch0:");
    //Serial.println(t->TC_RC);
    //Serial.print("Ch1:");
    //Serial.println(tt->TC_RC);


Here is the code I am using:

Microphone:
Code: [Select]

#include <AutoAnalogAudio.h>
#include "myRadio.h"

AutoAnalog aaAudio;

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

void setup() {

  Serial.begin(115200);
  Serial.println("Analog Audio Begin");

  aaAudio.begin(1,0);  //Setup aaAudio using ADC only
  aaAudio.autoAdjust = 0;
  aaAudio.adcBitsPerSample = 8;
  aaAudio.setSampleRate(16050);
  setupRadio();
}

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

uint32_t dispTimer = 0;
uint8_t channelSelection = 0;

void loop() {

  //Display the timer period variable for each channel every 3 seconds
  if (millis() - dispTimer > 3000) {
    dispTimer = millis();

    //TcChannel * t = &(TC0->TC_CHANNEL)[0];
    //TcChannel * tt = &(TC0->TC_CHANNEL)[1];

    //Serial.print("Ch0:");
    //Serial.println(t->TC_RC);
    //Serial.print("Ch1:");
    //Serial.println(tt->TC_RC);
  }

  // With autoAdjust disabled, getADC() will block until the ADC data is ready
  aaAudio.getADC(32);
  radio.writeFast(&aaAudio.adcBuffer,32);
}


Speaker:

Code: [Select]

#include <RF24.h>
#include <AutoAnalogAudio.h>
#include "myRadio.h"

AutoAnalog aaAudio;

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

void DACC_Handler(void) {
  aaAudio.dacHandler();   //Link the DAC ISR/IRQ library. Called by the MCU when DAC is ready for data
}

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

void setup() {

  Serial.begin(115200);
  Serial.println("Analog Audio Begin");

  aaAudio.begin(0, 1);  //Setup aaAudio using both DAC and ADC
  aaAudio.autoAdjust = 1;
  aaAudio.dacBitsPerSample = 12;
  setupRadio();
}

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

uint32_t dispTimer = 0;
uint8_t channelSelection = 0;

void loop() {

  //Display the timer period variable for each channel every 3 seconds
  if (millis() - dispTimer > 3000) {
    dispTimer = millis();

    //TcChannel * t = &(TC0->TC_CHANNEL)[0];
    //TcChannel * tt = &(TC0->TC_CHANNEL)[1];

    //Serial.print("Ch0:");
    //Serial.println(t->TC_RC);
    //Serial.print("Ch1:");
    //Serial.println(tt->TC_RC);
  }

  // Send serial commands to control which channel the audio is played on
  // DAC Channel 0, Channel 1, or both
  if (Serial.available()) {
    char dat = Serial.read();
    switch (dat) {
      case '0': channelSelection = 0; break; // Use DAC0 for output
      case '1': channelSelection = 1; break; // Use DAC1 for output
      case '2': channelSelection = 2; break; // Use both DAC0 and DAC1

    }
  }
}

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

uint32_t dynSampleRate = 0;

// See myRadio.h: Function is attached to an interrupt triggered by radio RX/TX
void RX() {

  while (radio.available(&pipeNo)) {                          // Check for data and get the pipe number

    if (pipeNo == 2) {
      radio.read(&dynSampleRate, 4);                          // Receive commands using pipe #2
      aaAudio.setSampleRate(dynSampleRate);                   // Pipe 2 is being used for command data, pipe 1 & others for audio data
    } else {

      radio.read(&aaAudio.dacBuffer16, 32);                   // Read the available radio data
     
      for (int i = 0; i < 16; i++) {                          //Convert signed 16-bit variables into unsigned 12-bit
        aaAudio.dacBuffer16[i] += 0x8000;
        aaAudio.dacBuffer16[i] = aaAudio.dacBuffer16[i] >> 4;
      }

      //Received 32 bytes: 16 samples of 16-bits each
      //Send them to the DAC using the channel selected via Serial command
      aaAudio.feedDAC(channelSelection, 16);
    }
  }
}



Now I can upload the WirelessSpeaker sketch  onto my Arduino. But when I try to upload the WirelessMicrophone sketch I get the following error:

Code: [Select]

C:\Users\...\AppData\Local\Temp\ccZEEVCy.ltrans0.ltrans.o: In function `__vector_13':
C:\Users\...\Documents\Arduino\libraries\AutoAnalogAudio-1.31.0\src\avr/AutoAnalogAudio.cpp:212: undefined reference to `DACC_Handler()'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano.



I could not find any speciffic solution to this. Any help would be appreciated since I realy don't know where to go with this.   :smiley-eek-blue:
Do I need to remove other Arduino Due specific stuff from the sketches to make it work?


Thank you very much for your time and effort.

guzu

So I have noticed that in the WirelessSpeaker sketch there is a definition of the DACC_Handler function.

Code: [Select]

void DACC_Handler(void) {
  aaAudio.dacHandler();   //Link the DAC ISR/IRQ library. Called by the MCU when DAC is ready for data
}



If I copy it to the other Sketch, it compiles.
I am wondering if this is needed? Or am I missing something else?

Thank you.

PaulS

Quote
I am wondering if this is needed?
Obviously.

Whether the DACC handler is the same in the microphone code as in the speaker code, or not, is going to be up to you to determine, experimentally.
The art of getting good answers lies in asking good questions.

guzu

Thank you @PaulS.

Probably the author considered that since the Microphone sketch only needs to convert from analog to digital, it does not need the DAC function. But the sketch does not compile otherwise.


Go Up