Stellaris/Tiva C WS28142b Driver

I’ve been playing around with WS2812b LEDs lately, and have been using my trusty TI Tiva C Series and Stellaris Launchpads as a controller for them.  The first thing I did with these was to use a timer to bit bang the control codes for LEDs on a GPIO pin.  This ended up being very resource intensive, so I started looking around for other options.  After a bit of digging into the datasheet, I realized that the SPI peripheral allows you to specify a byte to transfer onto the bus bit for bit, and that you can specify any clock rate you want for the peripheral.  This easily lends itself to creating a WS2812b driver that uses the SPI hardware to free up processor resources.  Further processor time can be freed by using the uDMA engine to handle transferring data from the LED control buffer to the SPI peripheral’s transmit buffer.  The resulting driver can be accessed on my github.

20141204_122810

In the future, I plan on making this driver more generic and better able to be run with multiple instances.  For example, it would be very nice to have three strips controlled by three separate SPI buffers, which right now is not a possibility with how the driver is architected.  I have a new architecture in mind that elegantly solves this problem, but I have not yet had the time, resources, or motivation to implement them.

3 Comments

  1. For all who are intending to reproduce the above please read my advises to avoid wasting time in getting it to run on the EK-LM4F120XL Stellaris Launchpad.
    Important:
    Stellarisware no longer compiles properly with CCS 6. Either use older CCS and Stellarisware or switch to Tivaware and CCS6. For Tivaware you have to change all include settings in the project properties.
    Additionally you have to follow TI’s device name change and rename the predefined symbol from PART_LM4F120H5QR to PART_TM4C1233H6PM. You also have to add the following symbol TARGET_IS_BLIZZARD_RA1.
    Now it compiles and runs.

    Question to the author:
    I could only get 42 LEDs to work – no more.
    Any idea, why this is the case?

    • Hi mosquito,

      The limitation of the 42 leds is related to the limitation of the uDMA engine to carry data. It is not documented ( I could not find it).
      To get around it, you must modify the Interrupt routine, and divide your uDMA transfers in successive chunks of max 42 leds (40 to be on the safe side), all before the final uDMA transfer of the reset signal. I was able to drive over 200 leds that way.
      How to hack the IRQhandler, that’s gonna be something for you to discover.

      Cheers, mate!

  2. Hi
    I have got a new type of built in IC SK6812 smd led strip,http://www.rgbledcolor.com/
    it is also three cables as ws2812b
    but I have a qustion,could it be controlled as ws2812b ?
    also how to control it by madrix software?

    If anyone could do me a favor will be great.

    Phil

    REPLY

Leave a Reply

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>