Just to show the principle I have a piece of code where I use the USART RX for receiving DMX using a DMX_Slave controller object . secondly I use the Software serial on the same USART to send the values every two seconds to my serial which I can monitor using the serial monitor tool.
Some more info that is not covered in my code example...
You can combine the DMX_Slave and DMX_Master from the library I'm using except you can not have them activated at the same time since you only have a single UDR register which is used for both transmitting data and receiving data on your USART.
So when the DMX_Master is enabled the DMX_Slave should be disabled and so on...... this is not included in my example but the principle stays the same... you can only use the UART for one thing at the time....On the shield I'm using you can enable and disable it via one of the digital pins that you select via a jumper...
#include <Conceptinetics.h>
#include <SoftwareSerial.h>
#define DMX_SLAVE_CHANNELS 10
//
// With this pin you can enable / disable the shield I'm using
// if HIGH the driver will be in shutdown state, RX will be Z state
//
const int dmxShieldEnablePin = 4;
// Configure a DMX slave controller
DMX_Slave dmx_slave ( DMX_SLAVE_CHANNELS );
const int ledPin = 13;
// the setup routine runs once when you press reset:
void setup() {
// Set start address to 1, this is also the default setting
// You can change this address at any time during the program
dmx_slave.setStartAddress (1);
// Set led pin as output pin
pinMode ( ledPin, OUTPUT );
pinMode ( dmxShieldEnablePin, OUTPUT );
// Enable DMX Shield
digitalWrite ( dmxShieldEnablePin, LOW );
// Enable DMX slave interface and start recording
// DMX data
dmx_slave.enable ();
}
// the loop routine runs over and over again forever:
void loop()
{
static unsigned long lastMillis = millis ();
//
// EXAMPLE DESCRIPTION
//
// If the first channel comes above 50% the led will switch on
// and below 50% the led will be turned off
// NOTE:
// getChannelValue is relative to the configured startaddress
if ( dmx_slave.getChannelValue (1) > 127 )
digitalWrite ( ledPin, HIGH );
else
digitalWrite ( ledPin, LOW );
// every two second send values to serial port with shield disabled
if ( millis () - lastMillis > 2000 )
{
// Stop dmx receiver and disable shield
dmx_slave.disable ();
digitalWrite ( dmxShieldEnablePin, HIGH );
char dmx_debug_str[52];
snprintf ( dmx_debug_str,
52,
"\r\n0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x ",
dmx_slave.getBuffer()[1],
dmx_slave.getBuffer()[2],
dmx_slave.getBuffer()[3],
dmx_slave.getBuffer()[4],
dmx_slave.getBuffer()[5],
dmx_slave.getBuffer()[6],
dmx_slave.getBuffer()[7],
dmx_slave.getBuffer()[8],
dmx_slave.getBuffer()[9],
dmx_slave.getBuffer()[10]
);
//
// In this example I used the software serial library
// to avoid a clah between the DMX library and the Hardware serial
// library... Of course you can manipulate the TX data register yourself
// as long you are not using the USART TX interupt
//
SoftwareSerial sw_serial ( 0, 1 );
sw_serial.begin ( 115200 );
for ( int i=0; i < 52 ; i++ )
sw_serial.write ( dmx_debug_str );
sw_serial.end ();
// Enable shield and start dmx receiver
digitalWrite ( dmxShieldEnablePin, LOW );
dmx_slave.disable ();
lastMillis = millis ();
}
}
The library I'm using can be downloaded from:
http://sourceforge.net/projects/dmxlibraryforar/?source=directory