--[[ ESP8266 connected to a 74hc595 port expander
By using SPI.
This DEMO sends serial data to one 74hc595, can easily be modified to use several.
It counts up from 0 to 255 and send it through SPI to the hc595.
SPI Connection:
GPIO12 (6) to MISO (NOT USED)
GPIO13 (7) to MOSI (hc595 pin 14 (DS))
GPIO14 (5) to CLK (hc595 pin 11 (SH))
GPIO15 (8) to CS (hc595 pin 12 (SS))
Master reset (/MR) i connect directly to VCC no need for resetting here unless you need it.
Output Enable (/OE) i connect directly to GND as i dont need high impedance mode on outputs.
]]
pin=8
spi.setup(1, spi.MASTER, spi.CPOL_HIGH, spi.CPHA_LOW, spi.DATABITS_8, 0);
gpio.mode(pin, gpio.OUTPUT)
for j=1,255,1 do
gpio.write(pin, gpio.LOW) --chip select avtive low
tmr.delay(20)
spi.send(1,j) --send the byte to hc595
gpio.write(pin, gpio.HIGH)
tmr.delay(100000) --delay so we can see whats going on
print(j)
tmr.wdclr() --Since we are delaying wery much we need to tell the system it has not crashed.
end
Lets get the party started and +1
[url=https://www.banggood.com/custlink/KvGGhGF4wG[/url]
I like ESP8266 and ESP8285 and ESP32
is cs pin(gpio15) necessary? i dont have access that pin
Since this uses the built in SPI hardware engine of the esp8266 I believe the hardware needs the CS pin...The hardware engine anticipates it is on an SPI bus in which the CS pin is pulled down...this needs to be sensed by the esp8266 SPI engine. In a uni-direction SPI interface MOSI or MISO the un-needed pin may be reassigned to be an ordinary GPIO pin.
Now GPIO15 is accessed on power up to determine flash mode...flash from uart needs it to be low. Some esp8266 pcb's have GPIO15 permanently wired to GND.
With a single device SPI bus this permanently low GPIO15 will still allow the esp8266 hardware spi to work.
picstart wrote:is cs pin(gpio15) necessary? i dont have access that pin
Since this uses the built in SPI hardware engine of the esp8266 I believe the hardware needs the CS pin...The hardware engine anticipates it is on an SPI bus in which the CS pin is pulled down...this needs to be sensed by the esp8266 SPI engine. In a uni-direction SPI interface MOSI or MISO the un-needed pin may be reassigned to be an ordinary GPIO pin.
Lets get the party started and +1
[url=https://www.banggood.com/custlink/KvGGhGF4wG[/url]
I like ESP8266 and ESP8285 and ESP32