3.1 Setup for DMX Receiver

The UART with protocol module can be configured as a DMX receiver with the following settings:
  • MODE<3:0> = 1010 - Selects the DMX mode
  • TXEN = 0 - Disables the transmitter
  • RXEN = 1 - Enables the receiver
  • RXPOL = 0 - Selects regular polarity
  • STP<1:0> = 10 for verifying the reception of 2 stop bits
  • UxP2 = Address of first byte to receive
  • UxP3 = Address of last byte to receive
  • UxBRGH:L = Value to achieve 250K baud rate
  • UxRXPPS = Code for desired input pin
  • Selected input pin should be made a digital input by clearing the corresponding ANSEL bit
  • ON = 1
Tip: Complete working demo for the DMX receiver can be found on the MPLAB® Xpress Cloud-Based IDE platform. See the MPLAB Press Code Examples.

Code snippet for setup as DMX receiver

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 = 0;        //Disable transmitter 
    U1CON0bits.RXEN = 1;        //Enable receiver
    U1CON2bits.RXPOL = 0;       //Standard polarity, RX pin will idle high 
    U1CON2bits.STP = 0b10;      //Recevie and verify 2 stop bits 

    //DMX data packet settings
    U1P1 = 0x00;                //Not used in DMX receiver  
    U1P2 = 0x10;                //Address of first byte of interest
    U1P3 = 0x20;                //Address of last byte of interest

    // Baud rate generator settings 
    U1CON0bits.U1BRGS = 1;      //High speed baud generation
    U1BRG = 0x3F;               //Value for U1BRG for Fosc = 64MHz  
    
    //PPS settings for RX functionality on pin RC7        
    ANSELCbits.ANSELC7 = 0;     //Make RC7 a digital I/O
    TRISCbits.TRISC7 = 0;       //Make RC7 an input 
    U1RXPPS = 0b010111;         //Assign RX functionality to RC7

    U1ON = 0x01;                //Turn on UART module
}