The UART module with built-in protocol support can be configured for DMX communication, which is an industry standard for stage lighting and other theatrical effects. The module manages the timing requirements and generates the correct sequence of individual events required as a DMX master, effectively reducing the amount of firmware needed for communication. Example 10-1 demonstrates how a device that has this UART module can be configured as a DMX Controller. Note that the PPS settings might not be the same for different devices, so minor changes to the code snippet may be required. The key configuration settings needed to configure the UART module as a DMX controller are:
1010
- selects the DMX mode1
- enables the transmitter0
- disables the receiver0
- selects regular polarity10
- for
two Stop bits1
void UART_Initialize(){
UxCON0bits.MODE = 0b1010; //Select DMX mode
UxCON0bits.TXEN = 1; //Enable transmitter
UxCON0bits.RXEN = 0; //Disable receiver
UxCON2bits.TXPOL = 0; //Standard polarity, TX pin will idle high
UxCON2bits.STP = 0b10; //2 stop bits
//DMX data packet settings
UxP1 = MAXCHANNELS-1; //Total number of data bytes - 1
UxP2 = 0x00; //Not used in DMX controller
UxP3 = 0x00; //Not used in DMX controller
//Baud rate generator settings
UxCON0bits.UxBRGS = 1; //High speed baud generation
UxBRG = 0x3F; //Value for UxBRG for Fosc = 64MHz
//PPS settings for TX functionality (May vary device to device)
ANSELxbits.ANSELxy = 0; //Make Rxy a digital I/O
TRISxbits.TRISxy = 0; //Make Rxy an output
RxyPPS = 0b010011; //Assign TX functionality to Rxy
UxON = 0x01; //Turn on UART module
}