12 DALI Communication using UART Module with Protocol Support

Digital Addressable Lighting Interface (DALI) is a widely used digital lighting control protocol that is used for intelligent lighting control for building automation. The UART module with protocol has built-in support for a DALI control device or controlgear. DALI communication uses Manchester encoding, which is performed using the UART hardware.

Tip: This section will only cover configuring the UART module for DALI communication. For more details about the protocol and how it can be implemented, see the UART with DALI Protocol Technical Brief.

A DALI control device is an application controller than is used to transmit commands to the other devices (light fixtures) connected on the same bus. The UART module has an available mode of operation that can be used for DALI communication that is configured using the UART Mode Select (MODE[3:0]) bits of the UART Control Register 0 (UCON0). Example 12-1 shows a code snippet of how the UART module can be configured as a DALI control device. A DALI control gear is a device that receives commands in order to control its output from a control device. In most applications, the control gear will be some type of light fixture that is connected on the same bus as the control device. Example 12-2 shows how the UART module can be configured as a DALI control gear. For both code examples, note that minor changes may be required, depending on the device being used.

DALI Control Device Configuration

void UART_Initialize(){
 UxCON0bits.MODE = 0b1000;         //Select DALI Control Device Mode
 UxCON0bits.TXEN = 1;              //Enable transmitter
 UxCON0bits.RXEN = 1;              //Enable receiver
 UxCON2bits.TXPOL = 0;             //Appropriate polarity for interface circuit
 UxCON2bits.STP = 0b10;            //Receive and verify 2 stop bits

 //data packet settings
 UxP1 = 0x01;                      //Forward Frame Hold Time (Half-bit Periods)
 UxP2 = 0x10;                      // Forward/backward frame threshold delimiter

 // Baud rate generator settings
 UxBRG = 0xCF;                     //Value for 1200 baud rate @ 1MHz

 //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
}

DALI Control Gear Configuration

void UART_Initialize(){
 UxCON0bits.MODE = 0b1001;         //Select DALI Control Gear Mode
 UxCON0bits.TXEN = 1;              //Enable transmitter
 UxCON0bits.RXEN = 1;              //Enable receiver
 UxCON2bits.TXPOL = 0;             //Appropriate polarity for interface circuit
 UxCON2bits.TXPOL = 0;             //Same as RXPOL
 UxCON2bits.STP = 0b10;            //Receive and verify 2 stop bits

 //data packet settings
 UxP1 = 0x01;                      //Back Frame Hold Time (Half-bit Periods)
 UxP2 = 0x10;                      //Forward/backward frame threshold
                                   //delimiter

 //Baud rate generator settings
 UxBRG = 0xCF;                     //Value for 1200 baud rate @ 1MHz

 //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

 //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
}