void sendSerial() { uint32_t nBitsSent = 0; /* Padding: we need to pre-pad We will send 15 12-bit values (180 bits) which is 22.5 8-bit SPI 8-bit bytes For every TLC5490 we actually need to send 16 12-bit values (192 bits in total) because that's what the TLC5490 serial comms expect. Since we are using only 15 of the output lines, the 16th value is unnecessary (we are not using OUT15) We also need to pad for the extra nibble (22.5 SPI above) So if we start by sending the empty 12-bit value, we are OK This padding needs to be done for every chip */ //~ padSPI(0); SPDR = 0; // First 8 bits of the empty 12-bit data while(!(SPSR & (1<= 192 *3) break; SPDR = 0; // First 8 bits of the empty 12-bit data while(!(SPSR & (1<2) { idxNextSendType = 0; } //~ ++idxNextSendType %= 4; // Prepare the next one for loading if (idxNextSendType==1) { // Case 1: Need to send the low nibble + padding toSPDR = dataByte<<4; } else { // Either way we need another new data in dataByte // if (idxChannel==0) { // Load next palette index nPixelsSent++; } dataByte = (idxChannel==0)?0xFF:0x00; if (++idxChannel>2) idxChannel = 0; //~ This fails: ++idxChannel %= 3; if (idxNextSendType) { // idxSendType == 2 // Case 2: Need to send pure data toSPDR = dataByte; } else { // idxSendType == 0 // Case 0: Need to send padding + high nibble toSPDR = dataByte >> 4; } } while(!(SPSR & (1<