UART Module with Protocol Support – Setting up a DMX Receiver

The UART module with protocol support can be configured as a DMX receiver and includes the built-in hardware support to automatically detect and respond to a valid Break condition. The UART with protocol module features a configurable address range, in which the module will ignore all the data bytes outside of the specified range in a DMX packet. In addition to the configurable address range, the module can also be setup to wait for and verify the reception of two Stop bits at the end of a DMX packet by setting the STP[1:0] bits of the UxCON2 register accordingly.

The start address of the configurable address range can be specified by writing to the UART Parameter 2 (UxP2) register and the end address can be set using the UART Parameter 3 (UxP3) register. The UART module only needs to be configured once as a DMX receiver and does not need to be updated for every DMX packet, unless the address range has changed. Example 11-1 demonstrates how a device that has this UART module can be configured as a DMX Receiver. The key configuration settings needed to configure the UART module as a DMX Receiver are:

Setting up a DMX Master (Controller) using the UART with Protocol Support

void UART_Initialize(){
 UxCON0bits.MODE = 0b1010;       //Select DMX mode
 UxCON0bits.TXEN = 0; 	       //Disable transmitter
 UxCON0bits.RXEN = 1; 	       //Enable receiver
 UxCON2bits.RXPOL = 0; 	      //Standard polarity, RX pin will idle high
 UxCON2bits.STP = 0b10; 	     //Recevie and verify 2 stop bits

 //DMX data packet settings
 UxP1 = 0x00; 		           //Not used in DMX receiver
 UxP2 = 0x10; 		           //Address of first byte of interest
 UxP3 = 0x20; 		           //Address of last byte of interest

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

 //PPS settings for RX functionality (May vary device to device)
 ANSELxbits.ANSELxy = 0; 	    //Make Rxy a digital I/O
 TRISxbits.TRISxy = 0; 	      //Make Rxy an input
 UxRXPPS = 0b010111; 	        //Assign RX functionality to RC7
 UxON = 0x01; 		           //Turn on UART module
}