Jump to content
43oh

DMX code examples


Recommended Posts

help me!

hello! you give me the principle diagram

Link the Tx pin on your MSP430 to the input of your MAX485.

I understand your english may be not that good, but your question is too broad and does not reflect any effort of your own. Any google query would have given you the principle diagram of a DMX controller

Link to post
Share on other sites
  • 5 weeks later...

 

DMX controller code which uses SPI (UCB) instead of UART (UCA.)

#include "msp430g2553.h"

typedef unsigned char u_char;
typedef unsigned int u_int;

#define DMX_OUT_PIN BIT7

void configMSP();
void sendDMX();
void sendByte(u_char byte);

const u_char START_SEQ[4] = { 0, 0, 0, 0x0F };

#define DATA_LENGTH 12
u_char dmxData[DATA_LENGTH] = { 0x55, 0x55, 0x55, 0x00, 0xFF, 0x00, 0x0F, 0x0F,
		0x0F, 0xFF, 0xFF, 0xFF }; // 4 RGB sets

u_int dataStart = 0;
u_int numberOfChannels = 3;
u_int dataEnd = 0;
u_int counter;

void main(void) {

	WDTCTL = WDTPW + WDTHOLD;
	configMSP();

	while (1) {
		_delay_cycles(1600000); // send DMX every 100ms
		counter++;
		if (counter == 20) { // switch data every 2s
			counter = 0;
			dataStart += numberOfChannels; // next data set
			if (dataStart == DATA_LENGTH)
				dataStart = 0;
			dataEnd = dataStart + numberOfChannels;
		}
		sendDMX();
	}
}

void sendDMX() {

	u_int c = 0;

	while (c < 4) {
		while (!(IFG2 & UCB0TXIFG))
			;
		UCB0TXBUF = START_SEQ[c];
		c++;
	}

	sendByte(0);

	c = dataStart;

	while (c < dataEnd) {
		sendByte(dmxData[c]);
		c++;
	}
}

void sendByte(u_char byte) {
	u_char first = byte << 1;
	u_char second = byte >> 7;
	second |= 0xFE;
	while (!(IFG2 & UCB0TXIFG))
		;
	_bic_SR_register(GIE);
	UCB0TXBUF = first;
	while (!(IFG2 & UCB0TXIFG))
		;
	UCB0TXBUF = second;
	_bis_SR_register(GIE);
}

void configMSP() {

	// DCO
	BCSCTL1 = CALBC1_16MHZ;
	DCOCTL = CALDCO_16MHZ;

	P1SEL |= DMX_OUT_PIN;
	P1SEL2 |= DMX_OUT_PIN;

	UCB0CTL0 |= UCCKPH + UCMST + UCSYNC;
	UCB0CTL1 |= UCSSEL_2;
	UCB0BR0 |= 0x40; // 16MHz/64 = 250k
	UCB0BR1 = 0;
	UCB0CTL1 &= ~UCSWRST;
}

I think, there is a mistake  (the start sequence definition) :

it should be   :  const u_char START_SEQ[4] = { 0, 0, 0, 0xFF };

instead of :const u_char START_SEQ[4] = { 0, 0, 0, 0x0F };

Link to post
Share on other sites

I think it shouldn't work, because of the SPI bit order 

 

{ 0, 0, 0, 0x0F }  : (8+8+8)*4us= 96us  break 4*4us=16us MAB   +  4*4us=16us extra break before every start bit  + startBit + dataBits + stopBits   (extra break confused receiver !)

{ 0, 0, 0, 0xFF } : (8+8+8)*4us= 96us break and 4*8us=32us MAB + startBit + dataBits + stopBits   (DMX512 standard)

Link to post
Share on other sites
  • 3 weeks later...

 

Time for the receiver.

 

Again, very simple code, receives 3 consecutive channels and stores the values in the array. 

Received values can then be used as PWM values to drive RGB LED.

#include "msp430g2553.h"

typedef unsigned char u_char;
typedef unsigned int u_int;

#define DMX_IN_PIN BIT1

void configMSP();

u_char data[3] = { 0, }; //
u_char dataCounter = 0;

u_char ucaStatus = 0;
u_char rxData = 0;

#define DMX_IDLE 0
#define DMX_BREAK 1
#define DMX_START 2
#define DMX_READY 3
#define DMX_RECEIVE 4

u_char dmxStatus = 0;
u_char dmxDataReady = 0;
u_int dmxChannel = 1;
u_int dmxLength = 3;
u_int dmxCounter = 0;

void main(void) {

    WDTCTL = WDTPW + WDTHOLD;
    configMSP();

    while (1) {
    }
}

void configMSP() {

    // DCO
    BCSCTL1 = CALBC1_16MHZ;
    DCOCTL = CALDCO_16MHZ;

    P1SEL |= DMX_IN_PIN;
    P1SEL2 |= DMX_IN_PIN;

    UCA0CTL0 |= UCSPB; // 2 stop bits
    UCA0CTL1 |= UCSSEL_2 + UCRXEIE + UCBRKIE;
    UCA0BR0 = 0x40; // 16MHz/64 = 250k
    UCA0BR1 = 0;
    UCA0MCTL = 0;
    UCA0CTL1 &= ~UCSWRST;
    IE2 |= UCA0RXIE;

    _bis_SR_register(GIE);
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void) {

    ucaStatus = UCA0STAT;
    rxData = UCA0RXBUF;

    if (ucaStatus & UCBRK) {
        dmxStatus = DMX_BREAK;
        ucaStatus = 0;
        dmxCounter = 0;
        dataCounter = 0;
    } else {
        switch (dmxStatus) {
        case DMX_IDLE:
            break;
        case DMX_BREAK:
            if (rxData == 0) {
                dmxStatus = DMX_START;
            } else {
                dmxStatus = DMX_IDLE;
            }
            dmxCounter++;
            break;
        case DMX_START:
            if (dmxCounter == dmxChannel) {
                dmxStatus = DMX_RECEIVE;
            } else {
                dmxCounter++;
                break;
            }
        case DMX_RECEIVE:
            data[dataCounter] = rxData;
            dataCounter++;
            if (dataCounter == dmxLength) {
                dmxStatus = DMX_IDLE;
                dmxDataReady = 1;
                break;
            }
            dmxCounter++;
            break;
        }
    }
}

 

 

Time for the receiver.

 

Again, very simple code, receives 3 consecutive channels and stores the values in the array. 

Received values can then be used as PWM values to drive RGB LED.

#include "msp430g2553.h"

typedef unsigned char u_char;
typedef unsigned int u_int;

#define DMX_IN_PIN BIT1

void configMSP();

u_char data[3] = { 0, }; //
u_char dataCounter = 0;

u_char ucaStatus = 0;
u_char rxData = 0;

#define DMX_IDLE 0
#define DMX_BREAK 1
#define DMX_START 2
#define DMX_READY 3
#define DMX_RECEIVE 4

u_char dmxStatus = 0;
u_char dmxDataReady = 0;
u_int dmxChannel = 1;
u_int dmxLength = 3;
u_int dmxCounter = 0;

void main(void) {

    WDTCTL = WDTPW + WDTHOLD;
    configMSP();

    while (1) {
    }
}

void configMSP() {

    // DCO
    BCSCTL1 = CALBC1_16MHZ;
    DCOCTL = CALDCO_16MHZ;

    P1SEL |= DMX_IN_PIN;
    P1SEL2 |= DMX_IN_PIN;

    UCA0CTL0 |= UCSPB; // 2 stop bits
    UCA0CTL1 |= UCSSEL_2 + UCRXEIE + UCBRKIE;
    UCA0BR0 = 0x40; // 16MHz/64 = 250k
    UCA0BR1 = 0;
    UCA0MCTL = 0;
    UCA0CTL1 &= ~UCSWRST;
    IE2 |= UCA0RXIE;

    _bis_SR_register(GIE);
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void) {

    ucaStatus = UCA0STAT;
    rxData = UCA0RXBUF;

    if (ucaStatus & UCBRK) {
        dmxStatus = DMX_BREAK;
        ucaStatus = 0;
        dmxCounter = 0;
        dataCounter = 0;
    } else {
        switch (dmxStatus) {
        case DMX_IDLE:
            break;
        case DMX_BREAK:
            if (rxData == 0) {
                dmxStatus = DMX_START;
            } else {
                dmxStatus = DMX_IDLE;
            }
            dmxCounter++;
            break;
        case DMX_START:
            if (dmxCounter == dmxChannel) {
                dmxStatus = DMX_RECEIVE;
            } else {
                dmxCounter++;
                break;
            }
        case DMX_RECEIVE:
            data[dataCounter] = rxData;
            dataCounter++;
            if (dataCounter == dmxLength) {
                dmxStatus = DMX_IDLE;
                dmxDataReady = 1;
                break;
            }
            dmxCounter++;
            break;
        }
    }
}
This code looks like it does not have the LED(ws2811) output. I would like the full code or file. h
thank you!
good luck!
Link to post
Share on other sites

 

This code looks like it does not have the LED(ws2811) output...

 

This is receiver code only, no driver, see my description:

 

 

Again, very simple code, receives 3 consecutive channels and stores the values in the array. 

Received values can then be used as PWM values to drive RGB LED.

 

However, there are examples of 2811 drivers on this forum, here for example.

Link to post
Share on other sites

This is receiver code only, no driver, see my description:

 

 

However, there are examples of 2811 drivers on this forum, here for example.

Can you help me code transmitted, received master and slaver DMX LED driver ws2811(led full color)
I needed it.
if there is one master code for 2 transmit slaver too good
thank you very much!
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...