SPI with shift registers 595 questions

hello guys,
while i was learning about SPI, i came across this tutorial in which the tutor doesn't use SPI library for shift register 74HC164, which doesn't have a latch pin,

1 - so what about 595 how would the SPI be done with 595 which has 3 pins that must be attached to arduino ?
2 - Is the Latch Pin of a shift register the SS used in SPI ?
3 - and what is the advantage of using the 164 which doesn't have a latch pin ?
4 - In SPI, are just the pins 11, 12, and 13 of arduino used for communication only ?

It depends on what you're doing. I was going to use a '164 to pass 8-bit data to a display. The latch would occur in the display controller with a transition on the WR line. There was no reason to have a latch on the shift register itself.

jboyton:
It depends on what you're doing. I was going to use a '164 to pass 8-bit data to a display. The latch would occur in the display controller with a transition on the WR line. There was no reason to have a latch on the shift register itself.

one of my questions is why the 164 doesn't have a latch and what is the reason to have a latch on a register ?

The 164 isn't a shift register, but it's flip-flops can be wired as a shift register.

one of my questions is why the 164 doesn't have a latch and what is the reason to have a latch on a register ?

The overall design allows you to shift-in a data pattern and then send/latch that output state to all of the outputs at once.

If you use the 164 the data will show-up at the outputs as it's shifted-through. If I want to turn-on one LED at the end of the chain, I have to turn-on all of the LEDs one at a time, 'till it gets to the end of the shift register. (That could happen very fast so you don't see the LEDs turn-on, but it might not be what you want.)

This isn't a perfect analogy, but it's like printing-out a "4" but instead of directly printing a 4, I have to print "1, 2, 3, 4", and stopping when I get to 4. If I have a latch, I still have to count to 4 but I don't print the results until I get to 4.

DVDdoug:
The 164 isn't a shift register, but it's flip-flops can be wired as a shift register.
The overall design allows you to shift-in a data pattern and then send/latch that output state to all of the outputs at once.

If you use the 164 the data will show-up at the outputs as it's shifted-through. If I want to turn-on one LED at the end of the chain, I have to turn-on all of the LEDs one at a time, 'till it gets to the end of the shift register. (That could happen very fast so you don't see the LEDs turn-on, but it might not be what you want.)

This isn't a perfect analogy, but it's like printing-out a "4" but instead of directly printing a 4, I have to print "1, 2, 3, 4", and stopping when I get to 4. If I have a latch, I still have to count to 4 but I don't print the results until I get to 4.

ahh ok thanks for that explanation :smiley:
it's like data do not go out until i tell u (by setting the latch pin)

DVDdoug:
The 164 isn't a shift register, but it's flip-flops can be wired as a shift register.

Mouser calls the 74HC164 a shift register.
And Texas Instruments calls the 74HC164 a shift register.

It just doesn't have a latch.

DVDdoug:
The 164 isn't a shift register, but it's flip-flops can be wired as a shift register.

jboyton:
Mouser calls the 74HC164 a shift register. And Texas Instruments calls the 74HC164 a shift register.

There's a reason for that.

It is a shift register. Nothing more, nothing less.

A 74xx595 is defined as a shift register plus a latch.

Simple as that. Two functions in one chip.

guys any idea about the other questions please ?

  1. It depends on what you want. Typically you'd connect SCK to the serial input clock, MOSI to the serial data input, and some other pin to the latching clock. After each SPI byte is transferred you'd have to strobe the latch pin. (If you chained N shift registers you could transfer N bytes at once before having to latch them.)

  2. You could use the SS pin but you don't have to. When the processor is configured to be an SPI master the SS pin has to be either an input held high or an output. If it's set up to be an output you can use the pin for just about anything you want, including clocking the latch on a shift register.

  3. Why use a 164 instead? If you don't need a latch it spares you having to clock it. And it has fewer pins and a smaller package.

  4. Your question is poorly phrased. The MOSI, MISO and SCK pins are digital pins 11, 12 and 13 respectively on the Uno. On other Arduinos they might be different. When the processor is configured to be an SPI master those pins can't be used as normal input/output pins. And as I mentioned already, the SS pin must be set as either an output pin or as an input pin and pulled high.

But you can turn off the SPI feature, use those pins for something else, and then turn SPI back on. I did this for one project where I needed a few more data lines for a non-SPI display. When I communicated with that display I turned off SPI and used the pins associated with SCK and MOSI as data outputs to it. When I communicated with the SPI devices in the project, I re-enabled SPI. The display didn't care about that as long as I wasn't clocking it. And the SPI devices didn't care when I was talking to the display since their chip selects were inactive.

A good read: gammon.com.au/spi

Next time, in addition to red and bold, increase the size of your font to the maximum allowed and also add a JPG of an atomic bomb exploding. Then you'll get an answer more quickly.

jboyton:
(If you chained N shift registers you could transfer N bytes at once before having to latch them.)

you mean if chained i just sink the data by the Q' ?

jboyton:
2. You could use the SS pin but you don't have to. When the processor is configured to be an SPI master the SS pin has to be either an input held high or an output. If it's set up to be an output you can use the pin for just about anything you want, including clocking the latch on a shift register.

but i have to use the SS always to address the device

jboyton:
4. Your question is poorly phrased. The MOSI, MISO and SCK pins are digital pins 11, 12 and 13 respectively on the Uno. On other Arduinos they might be different. When the processor is configured to be an SPI master those pins can't be used as normal input/output pins. And as I mentioned already, the SS pin must be set as either an output pin or as an input pin and pulled high.

so if i need to change the pins just from library or it's a hardware related too ?

jboyton:
A good read: gammon.com.au/spi

yes in fact i am using gammon site for reference and others of course

jboyton:
Next time, in addition to red and bold, increase the size of your font to the maximum allowed and also add a JPG of an atomic bomb exploding. Then you'll get an answer more quickly.

hahahahahahahahahaha ! :sweat_smile: good idea :stuck_out_tongue:
i always put the questions it's been a while in other font to be noticed more in the main post :slight_smile:

firashelou:
you mean if chained i just think the data by the Q' ?

The 595 has a serial output pin. You'd just connect that to the next shift register's input pin. The 164 doesn't have a serial output, but since it isn't latched you could use Q7.

but i have to use the SS always to address the device

You can use any digital output pin to drive a device's chip select.

so if i need to change the pins just from library or it's a hardware related too ?

It's hardware related.

ok thanks a lot for the help :smiley:

Actually, I'm not sure if you could chain the 164 part. You'd really need to look at the timing in the datasheet to see if there's a race condition between Q7 changing and the setup time for the input of the next register.

jboyton:
The 595 has a serial output pin. You'd just connect that to the next shift register's input pin. The 164 doesn't have a serial output, but since it isn't latched you could use Q7.

This is a bit like the previous confused reply.

The 74HC164 most certainly has a "serial output pin" which is Q7.

The 74xx595 has a nominated "serial output pin" only because the shift register is otherwise not exposed while in the 74HC164, all of the register is exposed.

jboyton:
Actually, I'm not sure if you could chain the 164 part. You'd really need to look at the timing in the datasheet to see if there's a race condition between Q7 changing and the setup time for the input of the next register.

The 74HC164 is edge-triggered. And in any case, apart from a single gate (and the datasheet indicates that this is in fact, present on all data inputs in the chain so there is no difference) chaining from one to the next is identical to chaining of stages within the chip.

Paul, thanks for the clarification. I'm frequently confused.

last thing guys i need to know,
if i removed the atmega from arduino uno and used it with a resistor a voltage regulator and capacitors and the clock + capacitor (as a summary the needed basic components for it to function properly) would that be enough if i need to program using SPI ? or the arduino board has something that makes the SPI works ?