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.

11 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?)

  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.

  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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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