Errors in a code with I2C, TimerOne and User defined USART Receive Interrupt

Hi All

I am working on MPU6050 sensor integration with Arduino Uno and I have started up building a project around it (mpu-6050.zip file attached).

For that, I am using standard MPU6050 and I2Cdev libraries. I do not want to use the builtin Arduino library of Serial. I am defining own USART Receive interrupt.

Here is my start up mpu-6050.ino code for testing:

#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <EEPROM.h>
#include <stdbool.h>
#include "TimerOne.h"
#include "I2Cdev.h"
#include "MPU6050.h"

#define USART_RXC_vect _VECTOR(18) // USART Rx Complete ISR

ISR(USART_RXC_vect)
{
}
void setup()
{
}

void loop()
{
}

While compiling this, I am getting following errors:

HardwareSerial0.cpp.o (symbol from plugin): In function `Serial':

(.text+0x0): multiple definition of `__vector_18'

sketch\mpu-6050.ino.cpp.o (symbol from plugin): (.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

Multiple libraries were found for "EEPROM.h"
Used: C:\Program
Multiple libraries were found for "Wire.h"
Used: C:\Program
exit status 1
Error compiling for board Arduino/Genuino Uno.

If I remove my own USART Receive Interrupt definition, the code gets compiled successfully.
My query is: Do I2C, TimerOne and USART conflict while being used in the same code in Arduino? I am asking this because my USART interrupt method is working fine individually (Please find the project "Serially_Controlled_DO.zip" attached herewith).

mpu-6050.zip (48.8 KB)

Serially_Controlled_DO.zip (1.12 KB)

I tried to compile your code on an UNO

#include <avr/interrupt.h> 
#include <avr/io.h> 
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <EEPROM.h>
#include <stdbool.h>
#include "TimerOne.h"
#include "I2Cdev.h"
#include "MPU6050.h"

#define USART_RXC_vect _VECTOR(18) // USART Rx Complete ISR

ISR(USART_RXC_vect)
{  
}
void setup() 
{
}

void loop() 
{
}

and it compiled with a few warnings, but no failure. check your libraries may be?

My code gives compilation errors for different Arduino IDE programmers like AVRISP mkII, AVR ISP, ArduinoISP and Arduino as ISP for Arduino Uno.

The programmer does not matter.

Your usart code conflicts with the built-in HardwareSerial library; I compiled with only TimerOne without an issue so one of the libraries that I don't have installed (I2Cdev or MPU6050) must cause the conflict.

Out of curiosity, why don't you want to use the standard Serial library?

I came to know that Timer1 conflicts with the working of I2C. So now I have removed Timer1 and I am using Timer0. I am still getting the same errors. If I am able to understand the problem, then the user defined USART Receive Interrupt conflicts with this MPU6050 library which mainly runs on I2C. So this seems to be a problem of conflict of USART (user defined) and I2C while they are being used in the same code.

Installed the libraries. Using IDE 1.8.5, same results as J-M-L; only warnings.

Where did you find that timer1 conflicts with I2C?