How to make dmx512 protocol by using arduino duemilanove

Hi
Is there anyone who can help me in this topic
I am making a DMX512 lighting protocol by using arduino duemilanove and dmx sheild
I am having problem in baud rate as the maximum baud rate of arduino duemilanove is 11500k bps.
but i need baud rate of 250k. ATmega 328 datasheet shows that I can get baud rate of 250k but I am not getting it on my oscilloscope.
can anyone help me please

priya02:
Hi
Is there anyone who can help me in this topic
I am making a DMX512 lighting protocol by using arduino duemilanove and dmx sheild
I am having problem in baud rate as the maximum baud rate of arduino duemilanove is 11500k bps.
but i need baud rate of 250k. ATmega 328 datasheet shows that I can get baud rate of 250k but I am not getting it on my oscilloscope.
can anyone help me please

DMX is not normal 8n1 serial like the arduino IDE expects you have to fiddle with registers to get it setup correctly. There are a pile of libraries out there that can take care of this for you.

Hi priya02,

Don't know anything about the Duemilanove but from memory DMX512 is more like RS422 instead of RS232 so may need extra circuitry to function properly.

A quick Google search yields...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237578617
http://arduino.cc/playground/DMX/DMXShield
http://arduino.cc/playground/Learning/DMX

I am making a dmx512 by using arduino duemilanove
I put ISR to send a dmx packet simultaneously
and in main function i am sending data by using faders
I connect the software serial ports with 25 pin serial port and want to see the output and command line in hyperterminal
I connected by using RS232 IC
I am getting junk ASCII characters but I want the decimal numbers going as data in DMX packet
Can anyone help me
I can put my program

#include<avr/io.h>
#include<avr/interrupt.h>
#include <avr/wdt.h>
#include<HardwareSerial.h>

unsigned char DMXbuffer[512];                  //the 512 DMX channels for a packet of 512 
unsigned char *DMXptr;
int analogPin1 = A1;
int analogPin2 = A2;
int analogPin3 = A3;
int analogPin4 = A4;

int main()
{
  while(1){
  Serial.begin(9600);
  unsigned int NUM_OF_CHANNEL;
  const char stx_pin = 8;  //use pin 8 as softwrae serial transmit pin
  const char srx_pin = 7;      //use pin 7 as software serial receiver pin
  pinMode(stx_pin, OUTPUT);
  unsigned char i=0;
  Serial.println("Enter value of DMXbuffer[] ");
    //unsigned long int val =hex_to_ascii(value);
  EIMSK |= (1 << INT0);    //enable external interrupt INT0
  EICRA |= (1 << ISC01);   //trigger INT0 on falling edge
  PCMSK2 |= (1 << PCIE2);
  PIND |= (1 << PIND1); 
  if (DMXbuffer[0]){ 
  unsigned long int value1 = analogRead(analogPin1);   // read the input pin
  Serial.println(stx_pin,value1);
  Serial.println(value1,HEX);
  PORTD&=~(1<<PIND1);  //disable interrupt
  }
  else if(DMXbuffer[1]){ 
  unsigned long int value1 = analogRead(analogPin2);   // read the input pin
  Serial.println(stx_pin,value1);
  Serial.println(value1,HEX);
  PORTD&=~(1<<PIND1);  //disable interrupt
  }
  else if (DMXbuffer[2]){ 
  unsigned long int value1 = analogRead(analogPin1);   // read the input pin
  Serial.println(stx_pin,value1);
  Serial.println(value1,HEX);
  PORTD&=~(1<<PIND1);  //disable interrupt
  }
  }
}



//interrupt service subroutine attached to INT0 vector
ISR(USART_TX_vect)
{             
  
  int txpin = 1;                  // serial transmit pin, which sends the outgoing data to the MAX481.
  pinMode(txpin,OUTPUT);   
  unsigned char  i; 

  unsigned long baud =250000;    // The baud rate for DMX is 230400bps, since each bit = 4 microseconds.
  unsigned long clockspeed = F_CPU;
  /* F_CPU is a predefined constant equal to the clock speed of the microcontroller.
  *  for the Arduino duomilanove it is 16000000.
  *  I'm going to dump it into clockspeed because I'm worried about it being a signed long,
  *  which could screw up the bitwise math I'm going to do on baudprescale, maybe. */

  unsigned long baudprescale;    
  /* The baud prescale that will be loaded into the
  *  UBRR0H and UBRR0L registers to set the USART baud rate */
  baudprescale = (((clockspeed / (baud * 16UL))) - 1); //
  DMXptr = &DMXbuffer[0];  
  UBRR0L = (uint8_t) baudprescale;
  UBRR0H = (uint8_t) (baudprescale >> 8);
  // Set frame format to 8 data bits, no parity, 1 stop bit.
  UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
  //enable transmission and reception
  UCSR0B |= (1<<RXEN0)|(1<<TXEN0);  
  DMXbuffer[0] = (unsigned char) analogRead (analogPin1);
  DMXbuffer[1] = (unsigned char) analogRead (analogPin2);
  DMXbuffer[2] = (unsigned char) analogRead (analogPin3);
  DMXbuffer[3] = (unsigned char) analogRead (analogPin4);

  
  DMXptr = &DMXbuffer[0];
  for ( i=0; i <= 512; i++)
  {
   while(!(UCSR0A & (1<<UDRE0)));
   UDR0 = *DMXptr++;
 } 
  DMXbuffer[0] = (unsigned char) analogRead (analogPin1);
  DMXbuffer[1] = (unsigned char) analogRead (analogPin2);
  DMXbuffer[2] = (unsigned char) analogRead (analogPin3);
  DMXbuffer[3] = (unsigned char) analogRead (analogPin4);
  
 }

Moderator edit: tags added, smileys removed.

Can Anyone help me to solve this problem
its really important for me
anybody der