shiftOut Timing Issue

I am wondering if shiftOut method (defined in wiring_shift.c) could add a delay parameter since not all devices can handle the default tight timing.

In a project I did recently, the shifted output was sometimes garbled. And I had to modify the code to add a slight delay between the writes to get it working.

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val)
{
        int i;

        for (i = 0; i < 8; i++)  {
                if (bitOrder == LSBFIRST)
                        digitalWrite(dataPin, !!(val & (1 << i)));
                        delay(5);
                else                        
                        digitalWrite(dataPin, !!(val & (1 << (7 - i))));
                        delay(5);
                digitalWrite(clockPin, HIGH);
                delay(5);
                digitalWrite(clockPin, LOW);
                delay(5);
        }
}

If the next version of the library could take a delay parameter, it would definitely be more useful.

I would think most shiftregisters can handle say 20 MHz just fine. For example the 74HC595 states 100 MHz as a typical shift out frequency. A datasheet for 74LS164 states a clock frequency of 36 MHz. The (normal) arduino at 16 MHz don't really approach those values for shifting out data.

Of course I don't know anything about your project, but I would think this has something to do with your schematics. There are a lot of things that can affect performance. Like long wires, noise, capacitance, load... to name a few.

I don't really know if a delay argument to shiftOut() would be useful except on rare occations, and also yet another argument to pass to the function. But on the other hand it could probably be educational if used with some example code to shift things out very slowly (like once a second or so). Then again this is not under my control :slight_smile:
Plus, you managed to hack your own version just fine.