Microchip | The Embedded Control Solutions Company Register Login
Browse All
Microchip Technology
 369 Code Snippets

DMX512 Receiver using PIC18FxxK83 with DMA

Microchip Technology

Check out this project's MPLAB Xpress Webpage to view the complete code example along with a detailed step by step write-up and description, or visit the PIC18F26K83 Device Product Page for more information.

About this Code Example

Note: This is a direct port of Ashish Makthal's Code Example for the PIC18F46K42 over to the PIC18F26K83 (See Here)


The PIC18FxxK42 family has a new UART peripheral which supports several protocols like DMX512, DALI and LIN. This project shows the implementation of a DMX512 receiver on a K42 family device.

The UART with protocol support has programmable address registers that determine what part of the 512 data byte stream should be received. These are the U1P2 and U1P3 registers. It is up to the user to program these registers with the start and end address of the required section of the full data stream.

The PIC18FxxK42 family of devices also have a two channel Direct Memory Access (DMA) module. The DMA module has programmable start/end addresses, counters, triggers and interrupts. This gives the user great flexibility in using the core to attend critical tasks while the DMA moves chunks of data in the background.


In this example, we will be using the HPC Curiosity board with the DMX-Click board and a 4x4 RGB LED Click board. The concept is that each HPC board will receive 3 bytes of RGB data and use that to control the color and intensity of the LEDs on board. It is assumed that there is a DMX Controller transmits the required RGB data.

The DMA is configured to receive these 3 bytes of RGB data through the UART receive buffer and store it in an array. The SPI module will later use this data to control the LEDs.

As mentioned earlier, the U1P2 and U1P3 registers of the UART module determine how many bytes of the full DMX packet is of interest. Only these bytes are received into the receive buffer. In real-world situations, the addresses of these devices can change dynamically, but in this example (for now) the address is hard-coded to 0x02.

Click Boards

The DMX click board used in this project is in the initial development phase. The schematic for this board is available in the "External Links" sections below.

The RGB LED click board has 16 WS2812 LEDs that can controlled using a single line. This board is available for purchase on the MikroElektonika website.

MCC Settings

Here are the setting used for the UART (DMX mode), SPI + CLC (to operate the LEDs). These settings were done using the Microchip Code Configurator - MCC. Open MCC to look at the settings of other modules like Timers etc. The DMA module was setup manually and will be available in MCC soon.

UART Settings:

SPI Settings:

CLC Settings:

DMA Settings:

Refer to the DMA_Initialize() function in the file main.c for further details.


  1. Setup the Start Address on the receiver boards using the addressing board. The End Address is calculated in code by adding an offset. e.g. Start address = U1P2 = 0x06 which implies that the End address = U1P3 = 0x08
  2. The DMX controller transmits the data packets. Refer to the DMX Controller example for more details.
  3. The UART module which is setup as the DMX receiver, waits for a Break condition to occur on the line.
  4. After this it accepts the first byte into the RX buffer and sets the U1RXIF flag.
  5. The DMA is triggered off this condition and moves the byte from the U1RXBUF to the DMX_Data array.
  6. The UART module will always accept the first byte as it is defined as the Start code in DMX universe. This determines what the next data bytes mean. In our case we are using the basic Start code = 0x00 case.
  7. Since the Start address is 0x06, the UART will wait until the 6th byte after the 1st byte has been accepted. The UART module will suppress the RXIF interrupts until the 6th byte after the 1st byte has been received.
  8. There isn't a need to clear the RXIF flag for the DMA to re-trigger. The event of receiving a byte in the U1RXBUF is what triggers the DMA.
  9. The UART will accept the 6th, 7th and 8th byte after the start code byte and ignore all the other bytes the DMX controller transmits. The UART module will be active when it observes a break condition on the bus again which signals that the controller is going to start a new data stream.
  10. The DMA will move these three bytes in to the array and reset it's counters for next operation automatically and wait for the UART trigger.
  11. Timer0 is used to create a 1s delay and this is used to check the status of the input pins that decide the Start address. These pins are read every second and the addresses are updated. This can be seen in the GetDMXAddress() function.


The DMX controller is on the left and the HPC Curiosity board on the right with Start Address = 0

The DMX controller is on the left and the HPC Curiosity board on the right with Start Address = 3

DMX receiver on the HPC board with the DMX-click and 4x4 LED Click


Release History

  • Dec 4, 2018

    Version: 1.0.0

    Initial Release

Download Contact the Developer

*Required Fields

  • Current Version:1.0.0
  • Created:Dec 4, 2018
  • Updated:Dec 4, 2018
  • Downloads:812
  • C Compiler:XC8 1.45
  • Development Tools:Curiosity HPC Board
  • Supported Devices:PIC18F26K83

Corporate News


Stay Connected

Stay up to date with the latest news from Microchip Technology.