Digging Into The APA102 Serial LED Protocol

[Tim] got his hands on some APA102 RGB LEDs, which are similar in function to the common WS2812 addressable LEDs seen in many projects we’ve featured. The advantage of APA102 LEDs is that they don’t have the strict timing requirements of the WS2812. These LEDs are controlled with a SPI bus that can be clocked at any arbitrary rate, making them easy to use with pretty much any microcontroller or embedded system.

After working with the LEDs, [Tim] discovered that the LEDs function a bit differently than the datasheet led him to believe. [Tim] controlled a strand of APA102 LEDs with an ATtiny85 and connected a logic analyzer between some of the LEDs. He discovered that the clock signal of the SPI interface isn’t just passed through each LED, it actually looks like it’s inverted on the output. After some investigation, [Tim] found that the clock signal is delayed by a half period (which looks like an inversion) before it’s passed to the next LED. This gives the next LED in the strand enough time for data on the data line to become valid before latching it in.

Since the clock is delayed, [Tim] discovered that additional bits must be clocked as an “end frame” to generate clock signals which propagate the remaining data to the end of the strand. Although the datasheet specifies a 32-bit end frame, this only works for strings of up to 64 LEDs. More bits must be added to the end frame for longer strands, which the datasheet doesn’t even mention. Check out [Tim]’s post for more information, where he walks you through his logic analysis of the APA102 LEDs.

17 thoughts on “Digging Into The APA102 Serial LED Protocol

  1. What are the main differences between the WS2801/APA102 and the WS2812B? I understand the first use SPI and the latter uses a different protocol which seems to be more complex and finicky to deal with, but what are the implications? With no external peripherals the SPI versions seem to be the only choice for a Raspi or a ESP8266, but when using a dedicated uC for the task, how large of an array can we control using the weakest uCs, such as an Arduino or an MSP430? Which has a better update rate, which has less lag and less flickering when dimmed?
    (probably not the best place to ask this, so where would be a good place to ask all of this?)

      1. How about try HD107s 16bits /8bits RGB pixel led chip with PWM refresh rate 28KHZ and transmission rate 40M HZ?,the updated version of apa102 pixel led chip..
        It is the fastest digital pixel led in the workd so far ,a creative breakthrough success for pixel led caree,
        it is Absolutely a best choice to replace original apa102 /apa102C(2016)/sk9822 LED/ws2812b/sk6812 LED.
        bec it is much more stable and faster and engery saving .
        HD107s Pixel led chip has on the market (including 5050-RGB: 5050-RGBW: 3535-RGB 2020-RGB)
        the HD107s 5050-RGBW and HD107s -5050-RGB with 16 bits will on marker next Month ,

  2. The datasheet is WRONG about the End Frame. 0xFFFFFFFF can’t be used to mark the end of the packet because it is the code for maximum intensity white. If 0xFFFFFFFF did mark the end of a packet, any time you attempted to set an LED to maximum white, the LED string will consider the transmission to be ended, and that is simply not the case.
    Sending 0xFFFFFFF at the end of a packet is interpreted as just another data frame. It will turn white the next LED after those you expected to update. Try if for yourself. Send a packet to just some of the LEDs in your string, such as the first 10 LEDs. You will see that the 11th LED will turn white because 0xFFFFFFFF is just another data packet.
    The APA102 does not require any end of data frames marker. Simply send as many Data Frames as reuquired then stop. The beginning of the next packet will begin with a Start Frame, which resets every APA102 back to their initial state.
    The reason for no need to mark the end of transmission is that each APA102 updates its LED as soon as it has received the 32 required bits. Other LED strings update all of the LEDs at the end of transmission, thus the need for a something to mark the end of transmission.
    My code does not send anything to mark the end of a packet of data frames, and it works as expected.
    Has anyone made sense out of the paragraphs on the bottom half of page 5?

    1. A critical assumption in these APA102 strips is that the entire strip is updated every refresh. In this case, the EOF 32 1’s will not affect anything as there are no LEDs after the end of your strip. A better way to understand it is that the 32 0’s at the beginning of the frame are actually the EOF as your code will simply be looping anyway.

      Short answer: the only way to update just LED 10 of a strip is to maintain state of all of the other x-1 LEDs and rewrite the strip to turn of 10. It all looks the same and the code is actually cleaner.

    2. Thanks Mike!
      Is the Start Frame necessary for the LEDs to emit, each time they are powered?

      If one didn’t care about the color/intensity values (i.e. just wanted something that randomly changed based on a random stream of data) could one just send a series of random values, or does the sequence need to start with the Start Frame of zeros else the LEDs won’t turn on?

      If the Start Frame is necessary, then I guess one could wait until the Start Frame is randomly generated (or maybe it never will be…) and then all data after that would just change the color/intensity values as there is no end frame… But if the Start Frame is not necessary, then it could just take those random values as data to start with…

  3. If you didn’t buy APA102 from Taiwan, so the LED should be APA102C, made in China. As the original APA102 LED is super expensive, But now APA102C havs already stopped producing, as Taiwan don’t send IC to China factory any more.
    If you still want APA102/APA102C SMD, please buy the APA107 LED, as this is the upgrade type of APA102, it is Independent research and development by ourself, APA107 was made in China, based on APA102 technology.

  4. Addressing false claims and IP theft:

    APA Electronic Co., Ltd. prefers not to invade a maker space such as this, but we feel the need to address some false claims being made by Newstar, who is offering counterfeit LEDs that are in direct violation of our intellectual property and patents in various countries. APA Electronic invented and holds the patent on addressable RGB LEDs with an integrated IC chip. Any claims by companies not authorized to sell APA LEDs are putting themselves and their customers in IP jeopardy.

    We did have a shortage of inventory for four (4) months of the APA-102C and APA-102 LEDs. During that time, we were only shipping to existing clients of ours while we re-designed and upgraded the IC. Unfortunately, the re-design took longer than we had anticipated. By late September 2018, there will be plenty of inventory of our 8-bit (256) APA-102C-5050 and APA-102-5050 LEDs.

    Our upgraded model 8-bit (256) models include:

    PWM refresh rate of +20kHz.
    Oscillator Frequency 30MHz
    Zero slow down when Dimming

    We stand fully behind all of our products, service and pricing. We do not take any shortcuts when it comes to materials or IC. The use of counterfeit and off-brand parts like the WS, SK, APA-107, etc. will only open end users to IP jeopardy. We would appreciate if you contacted us directly for any LED parts required for your project.

    http://www.apaelectronic.com
    http://www.neon-world.com

  5. NS107S pixel led, the upgrade of APA107 led:
    1, CLK+Data double wire transfer.
    2, PWM refresh rate can be +26kHz
    3, Max transfer speed is 30MHz.
    4, And NS107S with built-in sleep function, no work no electric consumption, very good for battery-powered application, (only NS107s.)

  6. How about try The HD107s 16bits /8bits RGB pixel led chip with PWM refresh rate 28KHZ and transmission rate 40M HZ?
    It is the fastest digital pixel led in the workd so far ,a creative breakthrough success for pixel led career,
    it is Absolutely a best choice to replace original apa102 /apa102C(2016)/sk9822 LED .
    bec it is much more stable and faster and engery saving .
    HD107s Pixel led chip has on the market (including 5050-RGB: 5050-RGBW: 3535-RGB 2020-RGB)
    the HD107s 5050-RGBW and HD107s -5050-RGB with 16 bits will on marker next Month ,
    Panasonic,, has won Tokyo Olympic lighting project in 2020 ,,and use our HD107s pixel led strip ,

    HD107s RGB pixel led chip with PWM refresh Rate 28KHZ and transmission rate 40MHZ
    Apa107 RGB pixel led chip with PWM refresh rate 26KHZ and transmission rate 30MHZ
    original apa102 RGB pixel led chip with PWM refresh rate 20KHZ and transmission rate 30MHZ (Gone)
    app102C rgb pixel led chip with PWM refresh Rate 20KHZ and transmission rate 20MHZ (fake apa102)
    sk9822 RGB pixel led chip with PWM refresh rate 4.7KHZ and transmission rate 15MHZ (fake apa102)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.