2.1 Setup for DMX Controller

The UART with protocol module can be configured as a DMX controller with the following settings:
  • MODE<3:0> = 1010 - Selects the DMX mode
  • TXEN = 1 - Enables the transmitter
  • RXEN = 0 - Disables the receiver
  • TXPOL = 0 - Selects regular polarity
  • STP<1:0> = 10 - for 2 stop bits
  • UxP1 = One less than the number of bytes to transmit (excluding the start code)
  • UxBRGH:L = Value to achieve 250K baud rate
  • RxyPPS = TX pin output code
  • ON = 1
Tip: Complete working demo for the DMX controller can be found on the MPLAB® Xpress Cloud-Based IDE platform. See the MPLAB Xpress Code Examples.

Code snippet for setup as DMX Controller

Note: This code example is written for PIC18F25K42. The PPS setting might vary for different devices.

void UART_Initialize(){
    //UART module settings      
    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 = MAXCHANNELS-1;       //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
}