user83108: Context
I am working on a project which includes 13 cascaded STMicroelectronics LED1642GWs. These LED drivers are essentially 16bit shift registers, whereby the buffered serial data can be loaded to a number of different registers dependant on the required function.
The function is selected through the use of "digital keys", which is selected by number of CLK cycles for which the LE (CS/SS) pin is HIGH. For example, LE being HIGH for 1-2 CLK cycles will switch the 16 outputs as per the buffered bits, whereas LE being HIGH for 3-4 CLK cycles will load the 16 bits to a brightness register.

Question
How can I toggle my LE/CS/SS pin for a specific number of SCLK cycles? I had intended to use the SPI Libary, however I'm not sure this can be supported.
Many Thanks!

user83108: I've achieve this by "bit-banging" via a modified shiftOut() of ArduinoCore-avr/cores/arduino/wiring_shift.c, essentially allowing for two data lines on the same clocking:
void keyedShiftOut(
  uint8_t dataPin,
  uint8_t clockPin,
  uint8_t latchPin,
  uint8_t bitOrder,
  uint16_t val,
  uint16_t key)
{
    uint8_t i;

    for (i = 0; i < 16; i++)  {
        if (bitOrder == LSBFIRST) {
            digitalWrite(dataPin, val & 1);
            val >>= 1;
            digitalWrite(latchPin, key & 1);
            key >>= 1;
        } else {    
            digitalWrite(dataPin, (val & 0x8000) != 0);
            val <<= 1;
            digitalWrite(latchPin, (key & 0x8000) != 0);
            key <<= 1;
        }
            
        digitalWrite(clockPin, HIGH);
        digitalWrite(clockPin, LOW);        
    }
}

I used this to implement the sequence described within the data sheet (Figure 24. Brightness register setting) to set all of my 16 Brightness Registers to a half setting (0x7FFF) with a timed LE providing the digital key. This scoped out as:

Running on my Arduino Nano 33 IoT this clocked at 150kHz which is sufficient for my application.

83108: <h2>Context</h2>
<p>I am working on a project which includes 13 cascaded STMicroelectronics <a href="https://www.st.com/en/power-management/led1642gw.html" rel="nofollow noreferrer">LED1642GWs</a>. These LED drivers are essentially 16bit shift registers, whereby the buffered serial data can be loaded to a number of different registers dependant on the required function.</p>
<p>The function is selected through the use of &quot;digital keys&quot;, which is selected by number of CLK cycles for which the LE (CS/SS) pin is HIGH. For example, LE being HIGH for 1-2 CLK cycles will switch the 16 outputs as per the buffered bits, whereas LE being HIGH for 3-4 CLK cycles will load the 16 bits to a brightness register.</p>
<p><a href="https://i.stack.imgur.com/6knUc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6knUc.png" alt="Digital Keys" /></a></p>
<h2>Question</h2>
<p>How can I toggle my LE/CS/SS pin for a specific number of SCLK cycles? I had intended to use the <a href="https://www.arduino.cc/en/Reference/SPI" rel="nofollow noreferrer">SPI Libary</a>, however I'm not sure this can be supported.</p>
<p><strong>Many Thanks!</strong></p>
 83108: <p>I've achieve this by &quot;bit-banging&quot; via a modified <code>shiftOut()</code> of <a href="https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring_shift.c" rel="nofollow noreferrer">ArduinoCore-avr/cores/arduino/wiring_shift.c</a>, essentially allowing for two data lines on the same clocking:</p>
<pre class="lang-c prettyprint-override"><code>void keyedShiftOut(
  uint8_t dataPin,
  uint8_t clockPin,
  uint8_t latchPin,
  uint8_t bitOrder,
  uint16_t val,
  uint16_t key)
{
    uint8_t i;

    for (i = 0; i &lt; 16; i++)  {
        if (bitOrder == LSBFIRST) {
            digitalWrite(dataPin, val &amp; 1);
            val &gt;&gt;= 1;
            digitalWrite(latchPin, key &amp; 1);
            key &gt;&gt;= 1;
        } else {    
            digitalWrite(dataPin, (val &amp; 0x8000) != 0);
            val &lt;&lt;= 1;
            digitalWrite(latchPin, (key &amp; 0x8000) != 0);
            key &lt;&lt;= 1;
        }
            
        digitalWrite(clockPin, HIGH);
        digitalWrite(clockPin, LOW);        
    }
}
</code></pre>
<p>I used this to implement the sequence described within the data sheet (Figure 24. Brightness register setting) to set all of my 16 Brightness Registers to a half setting (0x7FFF) with a timed LE providing the digital key. This scoped out as:</p>
<p><a href="https://i.stack.imgur.com/w01FK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w01FK.png" alt="ScopeOutput" /></a></p>
<p>Running on my Arduino Nano 33 IoT this clocked at 150kHz which is sufficient for my application.</p>
