Configuring SPI transmit format

Hey guys - trying to get some more details about how the SPI hardware works on the IMP (IMP001 specifically, at the moment). If my answer is in the docs somewhere then I’ve not spotted it…

Is it possible to set the number of bits that the SPI hardware shifts out during a transaction?

I’m trying to get a working with the Imp.

Each of the 24 output channels on this device requires 12bit of brightness data.

The shift register inside the device holds 288bit of data - after all 288 bits have been shifted in, toggling the latch pin updates the LEDs.

Ideally, I want to be able to loop through my LEDs and spi.write(brightness) for each one - but in order to do that I need to set the SPI hardware up to only shift out 12bits at a time.

Is that possible or am I going to have to shuffle all my nibble around, packing the values in to a blob so they can all be written out of the SPI port in one go?

Let me know what you think

The SPI peripheral driver only works on byte boundaries, so you can only send (or receive) any multiple of 8 bits.

As you said, you’d need pre-form a blob that contained all the LED brightnesses, then write it in one shot. This is going to be a lot more efficient too.

Alternatively you could write pairs of pixels as 2x12=24=3 bytes.

OK cool, as I suspected - thanks Hugo.

My nibble shifting byte pairing function is pretty much done now as per your suggestion.