1

So i'm working on a quadcopter controlled by the arduino UNO, and focusing in pin interrupts for the reciever. This is the code for the reciever.

unsigned long timer[4];
byte last_channel[4];
volatile int input[4];


void rx_initialize() {
  PCICR |= (1 << PCIE0);
  PCMSK0 |= (1 << PCINT0);
  PCMSK0 |= (1 << PCINT1);
  PCMSK0 |= (1 << PCINT2);
  PCMSK0 |= (1 << PCINT3);
  Serial.begin(9600);
}

ISR(PCINT1_vect) {

  timer[0] = micros();//Lire la valeur PWM en microsecondes

  //////////////////////////CHANNEL1/////////////////////////////
  if(last_channel[0] == 0 && PINB & B00000001){//vaut digitalRead(HIGH); mais en plus rapide
    last_channel[0] = 1;//le state est HIGH
    timer[1] = timer[0];//Lire combien de temps HIGH
  }
  else if(last_channel[0] == 1 && !(PINB & B00000001)){
    last_channel[0] = 0;//le state est HIGH
    input[0] = timer[0] - timer[1];
  }

  //////////////////////////CHANNEL2/////////////////////////////
  if(last_channel[1] == 0 && PINB & B00000010){//Rising
    last_channel[1] = 1;//le state est HIGH
    timer[2] = timer[0];//Lire combien de temps HIGH
  }
  else if(last_channel[1] == 1 && !(PINB & B00000010)){//Falling
    last_channel[1] = 0;//le state est HIGH
    input[1] = timer[0] - timer[2];
  }

  //////////////////////////CHANNEL3/////////////////////////////
  if(last_channel[2] == 0 && PINB & B00000100){//Rising
    last_channel[2] = 1;//le state est HIGH
    timer[3] = timer[0];
  }
  else if(last_channel[2] == 1 && !(PINB & B00000100)){//Falling
    last_channel[2] = 0;//le state est HIGH
    input[2] = timer[0] - timer[3];
  }

  //////////////////////////CHANNEL4/////////////////////////////
  if(last_channel[3] == 0 && PINB & B00001000){//Rising
    last_channel[3] = 1;//le state est HIGH
    timer[4] = timer[0];
  }
  else if(last_channel[3] == 1 && !(PINB & B00001000)){//Falling
    last_channel[3] = 0;//le state est HIGH
    input[3] = timer[0] - timer[4];
  }
}

I'm using various files for every other part of the quadcopter such as PID controlling and IMU Reading.

But avrdude tells me that I did a redefinition of 'void __vector_4()'. Itried to look into PinChangeInt.h in the Arduino library folder but still no solution to the problem.

Thank you for your help!

  • Did you look into using it? – Ignacio Vazquez-Abrams Jul 8 '16 at 10:38
  • Are you using SoftwareSerial perchance? – Majenko Jul 8 '16 at 10:45
  • Hello? Are you going to answer my query? – Majenko Jul 8 '16 at 13:42
  • Sorry i was using a library for PinChangeInterrupt and all vectors were declared in it. So i was declaring it twice and it was giving me errors. – Raphael Fluckiger Jul 8 '16 at 20:25
  • I wasn't using softwareSerial BTW. – Raphael Fluckiger Jul 8 '16 at 20:26
2

__vector_4() is just another name for PCINT1_vect(). The error message simply means that you have defined that function twice. One definition is explicit in the code you are showing to us. I cannot see the other definition: obviously you are not showing all of your code. Most likely that other definition lies inside some library you are using in your program.

Since you cannot define an ISR twice, you will have to use another PCINT which is not already in use. Or you could modify the library and try to merge it's PCINT1_vect() with yours.

BTW, the error message does not come from avrdude, it comes from the linker.

  • Thanks for everything guys. I was using a library that defined these vectors. – Raphael Fluckiger Jul 8 '16 at 14:10
  • The library I used defined the vectors. I just needed to comment them inside the library it worked fine. Thanks for everything! – Raphael Fluckiger Jul 8 '16 at 20:48
  • 1
    just commented the lines and VOILA. – Raphael Fluckiger Jul 8 '16 at 20:49
1

You should use the ISR(PCINT0_vect) instead of the ISR(PCINT1_vect).

Or if you want to use PCINT1:

PCICR |= (1 << PCIE1);
PCMSK1 |= (1 << PCINT8);
PCMSK1 |= (1 << PCINT9);
PCMSK1 |= (1 << PCINT10);
PCMSK1 |= (1 << PCINT11);

But them you have to change every PINB to PINC too as it uses a different PORT

  • I tried using your solution with PCINT0 and all corresponding pins(8, 9, 10, 11) but I still get the same error: – Raphael Fluckiger Jul 8 '16 at 12:12
  • redefinition of 'void __vector_3()' – Raphael Fluckiger Jul 8 '16 at 12:12
  • You should only use PCINT0 it the pins you already had and PCINT1 with 8 to 11. Changing both at the same time will give new errors – Janw Jul 8 '16 at 12:16
  • I mean i used this: – Raphael Fluckiger Jul 8 '16 at 12:28
  • void rx_initialize() { PCICR |= (1 << PCIE0); PCMSK0 |= (1 << PCINT0); PCMSK0 |= (1 << PCINT1); PCMSK0 |= (1 << PCINT2); PCMSK0 |= (1 << PCINT3); Serial.begin(9600); } ISR(PCINT0_vect) { – Raphael Fluckiger Jul 8 '16 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.