ESP32 & Shift register

kumart
Posts: 7
Joined: Thu Nov 30, 2017 8:24 pm

ESP32 & Shift register

Postby kumart » Fri Feb 02, 2018 5:29 pm

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.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: ESP32 & Shift register

Postby permal » Sat Feb 03, 2018 6:41 pm

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 & Shift register

Postby WiFive » Sat Feb 03, 2018 7:55 pm

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.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: ESP32 & Shift register

Postby permal » Sat Feb 03, 2018 8:00 pm

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.

ta-mat
Posts: 12
Joined: Thu Dec 21, 2017 4:07 pm

Re: ESP32 & Shift register

Postby ta-mat » Sat Feb 03, 2018 10:14 pm

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.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: ESP32 & Shift register

Postby kolban » Mon Feb 05, 2018 12:02 am

Mr Kumart,
If I may ask, what is your use case, design? How will you be using the shift register?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

kumart
Posts: 7
Joined: Thu Nov 30, 2017 8:24 pm

Re: ESP32 & Shift register

Postby kumart » Tue Feb 13, 2018 6:14 pm

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!

Who is online

Users browsing this forum: Accound, Google [Bot] and 46 guests