..
pinMode(pinstrobe, OUTPUT);
pinMode(pinclk, OUTPUT);
pinMode(pindata, OUTPUT);
// idle states according to the datasheet
digitalWrite(pinstrobe,1);
digitalWrite(pinclk,0);
..
// a function to send 19bits of unsigned int data, MSBFIRST
void senddata19bits( unsigned int data ) {
unsigned int i;
// start the data transfer
digitalWrite(pinstrobe,0);
for (i=0; i<19; i++) {
if (data & (1<<18)) {
digitalWrite(pindata,1); digitalWrite(pinclk,1); digitalWrite(pinclk,0);}
else {
digitalWrite(pindata,0); digitalWrite(pinclk,1); digitalWrite(pinclk,0);}
data = data << 1;
}
// end of the datatransfer
digitalWrite(pinstrobe,1);
}
..
A. Minimum Data Setup Time 15 ns
B. Minimum Data Hold Time 10 ns
C. Minimum Setup Strobe to Clock rising edge 120 ns
D. Minimum Clock High Pulse Width 40 ns
E. Minimum Clock Low Pulse Width 40 ns
F. Minimum Setup Clock rising edge to Strobe 50 ns
G. Minimum Strobe Pulse Width 120 ns
H. Minimum Sleep to Clock Setup Time 50 μs
I. Setup “Idle” Release to Output Enable 1 msYou can always slow data down to peripherals that can’t accept it at a high rate.
So don’t worry about the processor being too fast.
If you really want, there is a way to drop the processor speed to 48Mhz (instead of 72Mhz) and still retain USB, but below that USB will not run.
The lowest speed you can run is the external clock freq, which is normally 8Mhz on these boards. But I don’t recommend you reduce the processor speed, just put small delays into your code.
The easiest way to do that is something like
for(volatile int mydelay=0;mydelay<1000;mydelay++);
Below the analyzer’s output when doing (BluePill @72MHz)
senddata19bits(0x45765);
- shift19bit_fast.JPG (45.42 KiB) Viewed 441 times
Does it make any different if I use:
void loop() {
// put your main code here, to run repeatedly:
// a function to send 19bits of unsigned int data, MSBFIRST
senddata19bits(0b1000101011101100101);
delay(1000);
}
http://www.allegromicro.com/en/Products … ivers.aspx
Since it uses and uncommon lenght, 19bits, I wonder if you can pad with 0s at the start or the end, and send 24bits, which could be just 3 bytes with the SPI port.
I couldn’t find a reference to doing that, but if I was you I would try and see if it works.
I bet padding 0s works fine, either before the MSB or after the LSB. Probably only in 1 case, not both, but that’s enough. If so, you can format your data and send it with the spi port.
https://assets.nexperia.com/documents/d … HCT595.pdf
most likely i’m just going to bit bang them. SPI is nice, but for a start i’d try something ‘raw’.
does it really matter if that bit banged clock driving the shift register use those thin spikes like in pito’s timing diagram?
making the clocks look like those evenly spaced clock / timing diagrams on the data sheets seemed pretty tough to do with bit banging
& it may keep the rates pretty low as 1 jump round the loop seem to stretch quite a bit compared vs that thin clock pulse
(oh got an idea, i could make the clock pulse a thin notch and leave it high for a big fat pause as it jumps round the loop, but i’m not sure if that’s going to help though)
just found out 74hc595 shift registers are pretty cheap on aliexpress, going for some 10 pieces for ~ 50c (shipping included in some cases)
https://www.aliexpress.com/w/wholesale-74hc595.html
think it makes rather decent ‘io expanders’ e.g. like the adafruit motor shield
https://learn.adafruit.com/adafruit-motor-shield
Albeit at more cost than a BP plus shift registers
Had to say that the BP/MM form factor is super attractive as part of the reason and that after stumbling into $0.50 for 10x74hc595 shift registers, i got sufficiently impulsive and grabbed some shift registers. planning to use them in a keyboard with a BP/MM
i think the shift registers has a useful role to play with BP/MM, saves lots of pins for things that don’t need mhz speeds for (e.g. key pads, leds, 7 seg leds, 1602 lcds, etc )
the other thing is that shift registers allows one to split the ‘limbs’ (peripherals) from the ‘brain’ (mcu) so that one can swap the mcu as desired and still plug into a same peripheral module
![]()
I just thought I’d mention that in case you didnt have one of the V series boards ![]()
