1

I want to send DMX with my Arduino Mega 2560. I'm using the IDE 1.6.7

I tried the AVR -> DMX source code from Ulrich Radig and also the layout for the RS-485 transmission.

I modified the code to fit the ATMega2560 but when I upload the code nothing happens.

The only thing I didn't do is to use the 22 Ohm resistors, is that a problem?

Any idea?

Here is my circuit:

Photo of breadboarded RS-485 circuit

Here is the source

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

#define F_CPU 16000000
#include <util/delay.h>

#define DMX_BAUD 250000
#define DMX_BAUD_BREAK 80000
#define DMX_BAUD_BREAK_UBBR ((F_CPU+DMX_BAUD_BREAK*8)/(DMX_BAUD_BREAK*16)-1)
#define DMX_BAUD_UBBR ((F_CPU+DMX_BAUD*8)/(DMX_BAUD*16)-1)


volatile unsigned char dmx_buffer[512];


//############################################################################
//DMX Senderoutine
ISR (USART_TX_vect)
//############################################################################
{
  static unsigned int  dmx_channel_tx_count = 0;
  static unsigned char dmx_tx_state = 0;

  switch (dmx_tx_state)
  {
    case (0):
      UBRR0   = DMX_BAUD_BREAK_UBBR;
      UDR0 = 0; //RESET Frame
      dmx_tx_state = 1;
      break;

    case (1):
      UBRR0   = DMX_BAUD_UBBR;
      UDR0 = 0; //Start Byte
      dmx_tx_state = 2;
      break;

    case (2):
      _delay_us(10);
      //Ausgabe des Zeichens
      UDR0 = dmx_buffer[dmx_channel_tx_count];
      dmx_channel_tx_count++;

      if(dmx_channel_tx_count == 512)
      {
        dmx_channel_tx_count = 0;
        dmx_tx_state = 0;
      }
      break;
  }
}

void setup() {
 //Init usart DMX-BUS
 UBRR0   = DMX_BAUD_UBBR;
  DDRE |= (1<<PE1); //Output TXD Pin ATmega2560
  UCSR0B|=(1<<TXEN0)|(1<<TXCIE0); // TXEN0 Transmitter enable / TXCIE0 TX complete interrupt enable
  UCSR0C|=(1<<USBS0); //USBS0 2 Stop bits
  sei();//Globale Interrupts Enable
  UDR0 = 0;//Start DMX

}

void loop() {
  // put your main code here, to run repeatedly:
    dmx_buffer[4]=255;
    _delay_ms(1000);
    dmx_buffer[5]=255;
     _delay_ms(1000);
    dmx_buffer[6]=255;
    _delay_ms(1000);
    dmx_buffer[4]=0;
    _delay_ms(1000);
    dmx_buffer[5]=0;
     _delay_ms(1000);
    dmx_buffer[6]=0;
     _delay_ms(1000);

}
1
  • 1
    The resistors are probably required, as they are shown in the original circuit. When you say it does not work, what doesn't work exactly? Maybe try putting some debug statements in your code, which write to the serial monitor, to ensure that the setup(), loop() and ISR() functions are being called, as well as the expected case statements being executed. Commented Feb 1, 2016 at 6:55

1 Answer 1

0

The only thing I didnt do is to use the 22 Ohm resitors, is that a problem?

Yes, that's a huge problem. The resistors are there to prevent reflections from distorting the signal. Without them the best you can hope for is a garbled mess.

1
  • Well but it doesnt matter if I only use one DMX device if i remember correcetly, right? I just want to get an output somehow for now. Commented Jan 31, 2016 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.