2

I use the Arduino IDE 1.6.9

What I want is a DMX Receiver which receives 1 channel and displays it on the serial monitor. When I try to compile the code, I get the following error:

C:\Users\Helyx\AppData\Local\Temp\build25a76891c667e0896ec10beb77bd0478.tmp/core\core.a(HardwareSerial0.cpp.o): In function `__vector_25':

D:\Programme\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial0.cpp:48: multiple definition of `__vector_25'

sketch\DmxReceive.ino.cpp.o:C:\Users\Helyx\Documents\Arduino\DmxReceive/DmxReceive.ino:26: first defined here

d:/programme/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

exit status 1
Fehler beim Kompilieren.

Any ideas? Here is my code:

#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdio.h>

#define F_CPU 16000000


#define DMX_BAUD 250000
#define DMX_LOST_TIMEOUT 8000

volatile unsigned char dmx_buffer[10];
volatile unsigned int dmx_lost = DMX_LOST_TIMEOUT;

volatile unsigned int dmx_adresse = 1;



ISR (USART0_RX_vect)

{
static unsigned int dmx_channel_rx_count = 0;
static unsigned char dmx_valid = 0;
unsigned char tmp = 0;

tmp =  UDR0;

if(UCSR0A&(1<<FE0))
{
 if(dmx_channel_rx_count > 1)
 {
   dmx_lost = 0;
 }
 dmx_channel_rx_count = 0;
 dmx_buffer[0] = tmp;
 if(dmx_buffer[0] == 0)
 {
   dmx_valid = 1;
   dmx_channel_rx_count++;
 }
 else
 {
   dmx_valid = 0;
 }
 return;
}

if(dmx_valid)
{
 dmx_buffer[dmx_channel_rx_count] = tmp;
 if(dmx_channel_rx_count < 514)
 {
   dmx_channel_rx_count++;
 }
 return;
}
}



ISR (TIMER2_COMPA_vect)

{
 if(dmx_lost<DMX_LOST_TIMEOUT)
 {
   dmx_lost++;
 }
}

void setup()
{


EICRA |= (1<<ISC11)|(1<<ISC10); //The rising edge of INT1 generates an interrupt request
EIMSK |= (1<<INT1); //External interrupt request 1 enable

//Init usart DMX-BUS
UBRR0   = (F_CPU / (DMX_BAUD * 16L) - 1);
UCSR0B|=(1 << RXEN0 | 1<< RXCIE0);
UCSR0C|=(1<<USBS0); //USBS0 2 Stop bits
sei();//Globale Interrupts Enable


TCCR2A |= (1<<WGM21);
TCCR2B |= (1<<CS22|1<<CS21|1<<CS20);
TIMSK2 |= (1<<OCIE2A);
OCR2A = F_CPU/1024/1000 - 1; //Tick 1ms
Serial.begin(57600);

DDRC = (1<<PE3);
PORTB |= 0x3F;
PORTC |= 0xFF;
PORTC &=~(1<<PE3);

}

void loop()
{

if(dmx_lost==DMX_LOST_TIMEOUT)
{
  dmx_buffer[dmx_adresse] = 0;

}
Serial.print(dmx_buffer[dmx_adresse]);
}
1

The compiler/linker is providing the answer. There are at least two definitions of the ISR for UART0 RX. One in your code and one in HardwareSerial.

  • Ahhh i see. Is there a way to tell the compiler to use my definition and ignore the one from HardwareSerial? – Helyx Jan 30 '16 at 16:00
  • There are additional USARTs on a Mega that you could use for DMX. You would otherwise have to remove reference to Serial. – Mikael Patel Jan 30 '16 at 16:08
  • Hmm i'm pretty new to programming. I'm just using the arduino board to get a fast result and later i want to build my own circuit from the beginning. Thats why i try to avoid as much "Ardunio commands" as possible. I tried to uncomment the line in HardwareSerial0.cpp but that doesn't seem to work. – Helyx Jan 30 '16 at 16:13
  • Why is it trying to use the arduino library anyway? I didn't include anything arduino related – Helyx Jan 30 '16 at 16:16
  • But you have Serial.begin/print/etc in you code. And the Arduino IDE build add Arduino.h to your source code. This header then goes along and includes HardwareSerial.h. – Mikael Patel Jan 30 '16 at 16:46
0

If I understand you correctly, you want to receive serial data (in DMX format) on one serial port, and then display that data on the serial monitor (using a different serial port).

The Arduino Mega 2560 is an excellent choice, because it has 4 hardware UARTs.

Alas, there is really only 3 hardware UARTs that you can actually connect to external hardware. USART0 (the Mega pins labeled "TX0" and "RX0") are already connected to the USB interface; the Arduino calls that USART "Serial." (without a number).

I avoid connecting anything to the "TX0" or "RX0" pins on the Mega, so I can use "Serial." (USART0) for sending debugging messages to the serial terminal over the USB cable.

// doesn't compile
ISR (USART0_RX_vect)
{
    // ...
}
// ...
void loop()
{
    // ...
    Serial.print(dmx_buffer[dmx_adresse]);
}

This looks inconsistent to me. One part of your program is trying to use USART0 ("Serial.") for sending and receiving messages to the serial monitor on the PC. Another part of your program is trying to use the same USART0 ("Serial.") for sending and receiving messages on the DMX network.

Have you tried connecting the DMX interface to the other available hardware USARTs -- perhaps USART1 ("Serial1.", the pins labeled TX1 and RX1), or USART2 ("Serial2.", the pins labeled TX2 and RX2), or USART3 ("Serial3.", the pins labeled TX3 and RX3)? Then your code would look more like other people recieving DMX on an Arduino Mega -- (a), (b), (c), etc.:

// the ISR setup that the other DMX-on-Arduino-Mega people use:
ISR( USART3_RX_vect ){
    // ...
}
// ...
void loop(){
    // ...
    Serial.print(dmx_buffer[dmx_adresse]);
}

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.