DMX Library and HardwareSerial - Multiple definitions of __vector_36

Hi there.

I’m working on a home domotics system using an Arduino Mega. I’d like to use the following library: http://www.deskontrol.net/blog/arduino-four-universes-dmx-512-library/. Since the Mega has 4 UART hardwares, I’d like to use the 2nd one to drive the DMX. In the header of the DMX library I set it to only use UART1.

Now, when compiling I get the error:
core.a(HardwareSerial.cpp.o): In function __vector_36':* *C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/HardwareSerial.cpp:147: multiple definition of __vector_36’
Dmx\lib_dmx.cpp.o:C:\Program Files (x86)\Arduino\libraries\Dmx/lib_dmx.cpp:206: first defined here

These lines correspond to the following pieces of code:

lib_dmx.cpp

#if defined(USE_UART1)
    ISR (SIG_USART1_RECV)
    {
      ArduinoDmx1.Process_ISR_RX(1);
    }
  #endif

HardwareSerial.cpp (line with ISR in it)

#if defined(USART1_RX_vect)
  void serialEvent1() __attribute__((weak));
  void serialEvent1() {}
  #define serialEvent1_implemented
  ISR(USART1_RX_vect)
  {
    if (bit_is_clear(UCSR1A, UPE1)) {
      unsigned char c = UDR1;
      store_char(c, &rx_buffer1);
    } else {
      unsigned char c = UDR1;
    };
  }
#endif

My full program code is:

/*-----------------------------------------------------------------------------
		include files
------------------------------------------------------------------------------*/
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <lib_dmx.h>

#define DMX512  (0)

byte mac[] = { 0xDD, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,0,0,2); // TODO: assign ip address from DHCP
unsigned int multicastPort = 8888;
IPAddress multicastIp(239,0,0,57);

char packetBuffer[UDP_TX_PACKET_MAX_SIZE];

EthernetUDP Udp;

int sensorValue = 0;
int ledState = 0;
int DMXPin = 0;

void setup() {
  
  // DMX
  ArduinoDmx1.set_control_pin(DMXPin);
  ArduinoDmx1.set_rx_channels(1);
  ArduinoDmx1.set_tx_channels(5);
  ArduinoDmx1.init_tx(DMX512);
  
  Ethernet.begin(mac,ip);
  Udp.beginMulti( multicastIp, multicastPort );
  Serial.begin(9600);
  
}

void loop() {
  int packetSize = Udp.parsePacket();
  if(packetSize){
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++){
      Serial.print(remote[i], DEC);
      if (i < 3){
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer[0]);
    
    ArduinoDmx1.TxBuffer[0] = (int)packetBuffer;
  }
}

I’m also using an adjusted Ethernet Library that supports UDP multicast (found here: GitHub - aallan/Arduino: open-source electronics prototyping platform ).

I’m not that familiar with the interrupts on Arduino, but I really have no idea how to fix this. I want to use the first UART for debugging, the second for DMX, and the other ones should be for communication with other Arduino’s.

That library only works on the Arduino if HardwareSerial.cpp is not used, i.e. no Serial, Serial1, Serial2, Serial3 is used.

To make it work, modify your HardwareSerial.cpp so that your posted excerpt looks like this:

#if defined(USART10_RX_vect)
  void serialEvent1() __attribute__((weak));
  void serialEvent1() {}
  #define serialEvent1_implemented
  ISR(USART1_RX_vect)
  {
    if (bit_is_clear(UCSR1A, UPE1)) {
      unsigned char c = UDR1;
      store_char(c, &rx_buffer1);
    } else {
      unsigned char c = UDR1;
    };
  }
#endif

Note the changed ifdef line at the start, this way the Serial1 object is not usable but you have the serial reception interrupt free for your library to use.