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:
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);
}
setup()
,loop()
andISR()
functions are being called, as well as the expected case statements being executed.