• AVR Freaks

Trying to figure out DMX mode with 18F45K25 UART

New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2019/07/04 06:16:51
  • Location: Lewisburg PA USA
  • Status: offline
2019/07/18 07:56:42 (permalink)

Trying to figure out DMX mode with 18F45K25 UART

After reading TB3204, "DMX-512 using the UART with Protocol Support", I am trying to get a simple DMX Par light to work with a signal sent from a 18F45K25 as a DMX controller. The fixture is in 4 channel mode where CH1 is the master dimmer, CH2 is R, CH3 is G, and CH4 is B. I am new to PIC programming but have experience with Arduino and have a vague understanding of C.
I am working with a Curiosity HPC board. The fixture is connected to the board via an inexpensive RS-485 board that uses a MAX485 chip. The fixture is set to address 1. The system clock is set to HFINTOSC and 64_MHz
The code I am trying to make work is:
1. UART1.c

void UART1_Initialize(void)
//UART module settings
//From Microchip document TB3204
U1CON0bits.MODE = 0b1010; //Select DMX mode
U1CON0bits.TXEN = 1; //Enable transmitter
U1CON0bits.RXEN = 0; //Disable receiver
U1CON2bits.TXPOL = 0; //Standard polarity, TX pin will idle high
U1CON2bits.STP = 0b10; //2 stop bits

//DMX data packet settings
U1P1 = 511; //Total number of data bytes - 1
U1P2 = 0x00; //Not used in DMX controller
U1P3 = 0x00; //Not used in DMX controller

// Baud rate generator settings
U1CON0bits.U1BRGS = 1; //High speed baud generation
U1BRG = 0x3F; //Value for U1BRG for Fosc = 64MHz

//PPS settings for TX functionality on pin RC6
ANSELCbits.ANSELC6 = 0; //Make RC6 a digital I/O
TRISCbits.TRISC6 = 0; //Make RC6 an output
RC6PPS = 0b010011; //Assign TX functionality to RC6
U1ON = 0x01; //Turn on UART module


2. main.c

int universe[512];
int channel;
void set_up_universe(void);
Main application
void main(void)
// Initialize the device

set_up_universe(); // Create universe data all 0
universe[1] = 255; // Add some inrensity data
universe[2] = 255;
universe[3] = 255;
universe[4] = 255;
universe[5] = 255;
universe[6] = 255;
universe[7] = 255;

// If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
// If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global Interrupts
// Use the following macros to:
// Enable the Global Interrupts
// Disable the Global Interrupts
    while (1)
        // Send universe of data
        for (channel = 1; channel <= 512; channel ++)
            U1TXB = universe[channel];
void set_up_universe(void)
    for (channel=1; channel <= 512; channel++)
        universe[channel] = 0;

When I run main.c I see DMX-looking data on my o-scope (RIGOL DS1054) from RC6. When I run with no delay, the fixture's red LEDs blink on 3 times about a second and then there is a long pause, about 5 seconds. Because I thought the way I am sending data might be fouling up the timing of the DMX, I started experimenting with delays before the packet starts. 
When I run with __delay_us(50), the fixture's blue LEDs come on for about 3 seconds and the red LEDs flash on and off for a couple of seconds. 
When I run with __delay_us(60), the fixture's green LEDs flash constantly at about 1 sec. At __delay_us(70) the blue and green LEDs flash constantly at about 1 sec. 
At __delay_us(90) nothing happens. 
If I understood how this was supposed to work better, I would know what the timing clues tell me, but, alas, I don't. My assumption is that what should be happening is all LEDs should on constantly. The problem could be with timing and/or my poor code.
I'm not sure what to try next. Can anyone suggest how to debug this?  Many thanks in advance. 
I should perhaps note that the fixture works as it is supposed to when used with the Arduino DMX library.

Peter R. Wiley
I feel a lot more like I do now than I did when I came in.

1 Reply Related Threads

    Super Member
    • Total Posts : 1507
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: Trying to figure out DMX mode with 18F45K25 UART 2019/07/18 09:30:37 (permalink)
    Continue only here  https://www.microchip.com/forums/m1105572.aspx
    Jump to:
    © 2019 APG vNext Commercial Version 4.5