Configuring .cpp build files.

Hi everyone,

I’m hoping that someone out there can give me a helping hand, or at least point me in the right direction for some documentation.

I’m currently working with DMX (similar to rs485) and a Mega2560. The library that came with the shield currently provides an example to read from serial port 0 (pins 0 & 1). However, I need those pins to debug the software as I go along, and as such, have rerouted the pins to work with Serial2 (pins 16 & 17).

When i go to compile my program, I receive the following error:

Arduino: 1.6.5 (Windows XP), Board: “Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)”

C:\DOCUME~1\Operator\LOCALS~1\Temp\build7681672645968544671.tmp/core.a(HardwareSerial0.cpp.o): In function __vector_25': C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial0.cpp:48: multiple definition of __vector_25’
Conceptinetics-2\Conceptinetics.cpp.o:C:\Program Files\Arduino\libraries\Conceptinetics-2/Conceptinetics.cpp:1163: first defined here
c:/program files/arduino/hardware/tools/avr/bin/…/lib/gcc/avr/4.8.1/…/…/…/…/avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
collect2.exe: error: ld returned 1 exit status
Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

What I understand from this error is that in my program I am trying to use Serial.print to read out data to my computer when the DMX library I’m using is trying to use that pin for reading DMX data.

Having a look at the .cpp build file that was included at the top of the .ino file, I see the following:

#if defined (USE_DMX_SERIAL_0)

    #if defined (USART__TXC_vect)
      #define USART_TX USART__TXC_vect
    #elif defined(USART_TX_vect)
      #define USART_TX  USART_TX_vect
    #elif defined(USART0_TX_vect)
      #define USART_TX USART0_TX_vect
    #endif 

    #if defined (USART__RXC_vect)
      #define USART_RX USART__RXC_vect
    #elif defined(USART_RX_vect)
      #define USART_RX  USART_RX_vect
    #elif defined(USART0_RX_vect)
      #define USART_RX USART0_RX_vect
    #endif 

    #if defined UDR
      #define DMX_UDR UDR
    #elif defined UDR0
      #define DMX_UDR UDR0
    #endif

    #if defined(UBRRH) && defined(UBRRL)
      #define DMX_UBRRH UBRRH
      #define DMX_UBRRL UBRRL
    #elif defined(UBRR0H) && defined(UBRR0L)
      #define DMX_UBRRH UBRR0H
      #define DMX_UBRRL UBRR0L
    #endif

    #if defined(UCSRA)
      #define DMX_UCSRA UCSRA
    #elif defined(UCSR0A)
      #define DMX_UCSRA UCSR0A
    #endif

    #if defined(UCSRB)
       #define DMX_UCSRB UCSRB
    #elif defined (UCSR0B)
       #define DMX_UCSRB UCSR0B
    #endif

    #if defined(TXEN) && defined(TXCIE)
        #define DMX_TXEN TXEN
        #define DMX_TXCIE TXCIE
    #elif defined(TXEN0) && defined(TXCIE0)
        #define DMX_TXEN TXEN0
        #define DMX_TXCIE TXCIE0
    #endif

    #if defined(RXEN) && defined(RXCIE)
        #define DMX_RXEN RXEN
        #define DMX_RXCIE RXCIE
    #elif defined(RXEN0) && defined(RXCIE0)
        #define DMX_RXEN RXEN0
        #define DMX_RXCIE RXCIE0
    #endif

    #if defined(FE)
      #define DMX_FE FE
    #elif defined(FE0)
      #define DMX_FE FE0
    #endif

    #define RX_PIN 0
    #define TX_PIN 1

#elif defined (USE_DMX_SERIAL_1)
    #define USART_RX USART1_RX_vect
    #define USART_TX USART1_TX_vect
    #define DMX_UDR UDR1
    #define DMX_UBRRH UBRR1H
    #define DMX_UBRRL UBRR1L
    #define DMX_UCSRA UCSR1A
    #define DMX_UCSRB UCSR1B
    #define DMX_TXEN TXEN1
    #define DMX_TXCIE TXCIE1
    #define DMX_RXEN RXEN1
    #define DMX_RXCIE RXCIE1
    #define DMX_FE FE1
    #define RX_PIN 19
    #define TX_PIN 18
#elif defined (USE_DMX_SERIAL_2)
    #define USART_RX USART2_RX_vect
    #define USART_TX USART2_TX_vect
    #define DMX_UDR UDR2
    #define DMX_UBRRH UBRR2H
    #define DMX_UBRRL UBRR2L
    #define DMX_UCSRA UCSR2A
    #define DMX_UCSRB UCSR2B
    #define DMX_TXEN TXEN2
    #define DMX_TXCIE TXCIE2
    #define DMX_RXEN RXEN2
    #define DMX_RXCIE RXCIE2
    #define DMX_FE FE2
    #define RX_PIN 17
    #define TX_PIN 16
#elif defined (USE_DMX_SERIAL_3)
    #define USART_RX USART3_RX_vect
    #define USART_TX USART3_TX_vect
    #define DMX_UDR UDR3
    #define DMX_UBRRH UBRR3H
    #define DMX_UBRRL UBRR3L
    #define DMX_UCSRA UCSR3A
    #define DMX_UCSRB UCSR3B
    #define DMX_TXEN TXEN3
    #define DMX_TXCIE TXCIE3
    #define DMX_RXEN RXEN3
    #define DMX_RXCIE RXCIE3
    #define DMX_FE FE3
    #define RX_PIN 14
    #define TX_PIN 15
#endif

It’s pretty clear that whoever made the build file has allowed for the extra 3 serial comms that the mega provides to be used with this shield. However I am completely stumped as to how I can enable them to be used. Is there something I need to define in my .ino file that will point to the serial port that I want to use?

I hope I have made myself clear enough. Please feel free to ask any questions. I have uploaded the example .ino file I was working with, along with the .cpp and .h file.

Thanks for your time and looking forward to hearing from you :slight_smile:

Conceptinetics.h (11.6 KB)

Conceptinetics.cpp (34.8 KB)

DMX_Slave.ino (3.14 KB)

Find the line "#define USE_DMX_SERIAL_0" and change it to "#define USE_DMX_SERIAL_2"

johnwasser: Find the line "#define USE_DMX_SERIAL_0" and change it to "#define USE_DMX_SERIAL_2"

Thanks john, I found the definition in the header file and changed that round.

If I now initialize the default serial port so I can read in some data to my computer and debug, I get this when I attempt to use any of the serial commands:

core.a(HardwareSerial.cpp.o): In function `__vector_51':
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.cpp:162: multiple definition of `__vector_51'
Conceptinetics\Conceptinetics.cpp.o:C:\Program Files\Arduino\libraries\Conceptinetics/Conceptinetics.cpp:1162: first defined here
c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

I will inspect the .cpp file and see if there is anything I can do.

Thanks again.

Looks like the DMX library is defining an ISR for the Serial interrupt even when it is using a different port for I/O. The ISR declarations should probably have similar #ifdef logic so the only the needed ISR is declared.