Page 1 of 1
ESP32 & Shift register
Posted: Fri Feb 02, 2018 5:29 pm
by kumart
Hey guys
I would like to connect a 74HC595 shift register to my ESP32 Thing.
Has anyone of you had any experience with ESP32 and a shift register? Is it possible to connect it via HSPI or VSPI?
Thanks for your help.
Re: ESP32 & Shift register
Posted: Sat Feb 03, 2018 6:41 pm
by permal
74HC595 is not an SPI device, so no you cannot. You could however simply use any four pins to control it. If you are not tight on pins, you could get the same logic directly on the pins of the ESP32 by holding the output value in memory and setting the outputs accordingly, just beware of the voltage levels.
Re: ESP32 & Shift register
Posted: Sat Feb 03, 2018 7:55 pm
by WiFive
permal wrote:74HC595 is not an SPI device, so no you cannot. You could however simply use any four pins to control it. If you are not tight on pins, you could get the same logic directly on the pins of the ESP32 by holding the output value in memory and setting the outputs accordingly, just beware of the voltage levels.
It is pretty common to use spi to generate the bit stream for a shift register. There are a few examples for esp8266 and esp32.
Re: ESP32 & Shift register
Posted: Sat Feb 03, 2018 8:00 pm
by permal
WiFive wrote:
It is pretty common to use spi to generate the bit stream for a shift register. There are a few examples for esp8266 and esp32.
Well, ofc you can use SPI to generate bitstreams. If that is what OP is asking about, sure. It's not the same as actual SPI communication though, which is what I read the question as.
Re: ESP32 & Shift register
Posted: Sat Feb 03, 2018 10:14 pm
by ta-mat
Short answer is no. But yes.
(1) No. Since 74HC595 is not an SPI device, as @permal described, you can't use 74HC595 as SPI device.
(2) But yes. You can use ESP32's SPI as bit stream output device for 74HC595 as @WiFive wrote.
If you choose (2), I recommend you to refer "7. SPI" in the ESP32 technical reference manual. You should mainly set the following registers/bits:
Code: Select all
spi_dev_t.ctrl.wr_bit_order (MSB/LSB first)
spi_dev_t.user2.usr_command_bitlen (Command phase)
spi_dev_t.user1.usr_addr_bitlen (Address phase)
spi_dev_t.user.usr_dummy (Dummy phase)
spi_dev_t.user1.usr_dummy (Dummy phase)
Also esp-idf's SPI driver code may help you.
Re: ESP32 & Shift register
Posted: Mon Feb 05, 2018 12:02 am
by kolban
Mr Kumart,
If I may ask, what is your use case, design? How will you be using the shift register?
Re: ESP32 & Shift register
Posted: Tue Feb 13, 2018 6:14 pm
by kumart
Hey guys
Thanks for your answers! Yes, i know that 74HC595 is not an SPI-device, but i heard that SPI can be used to create a bitstream for the shift register.
@kolban: I would like to trigger a sound module with buttons and via Webserver-option. To select the sound which I want to play I must trigger ten optocouplers. I am planning to use a shift register because i have too few GPIOs to control the button-LEDs and the optocoupler.
@ta-mat: Thank you, i will try this.
Is it correct if I use
-HSPI_CLK for SRCLK of 54HC595,
-HSPI_D for SER (Data)
-any GPIO for OE and another GPIO for RCLK?
Thanks for your help!