use shfit register with other spi devices

Hello all!

I'm working on a project and I'm a bit stuck now. I have an esp8266 to control a tft screen w/ touchscreen. Both of them use the SPI protocol to communicate. I want to add an shift register because I need more output pins. If I would use the shift-out library, how do I make sure that only one spi device is active at the time? Is this even necessary?

Thanks in advance and kind regards,

Rens van Breukelen

If I would use the shift-out library, how do I make sure that only one spi device is active at the time? Is this even necessary?

The shiftOut() function of the IDE does not use SPI. But to answer your question: SPI device always have a SS pin (slave select). They stay inactive as long as this pin is pulled HIGH. If you ensure that the SS pin of only one device is LOW at any given time you won't have a collision.

I know but the shift register uses the same data and clock lines as my spi devices. The ss pins are controlled via the default spi library, and I have no clue on how to make sure only one ss is low.

I know but the shift register uses the same data and clock lines as my spi devices.

Then the wiring is wrong. It might help to have a wiring diagram and links to the used hardware.

The ss pins are controlled via the default spi library, and I have no clue on how to make sure only one ss is low.

The library should take care of this if you use the beginTransaction() and endTransaction() methods.

ESP8266: Connection to SN74HC595 - techtutorialsx. This is the tutorial I used for the connections. I now know that only one device is active at the time (quite logical, actually, because the avr cannot do multiple things at the same time). I already had the PCB's made, with these connections. Is there any way I can still make this work? I tried it and it doesn't work right now.

You have a pcb made so you should have a schematic that goes with it. Post a image version of that schematic here.

That should basically show us how you currently have thongs connected. Next we can talk about the shift register.

I’m on vacation right now, so I don’t have the schematics with me. It’s basically like the one in the attachments.

Oh i f*cked up the schematics. :confused: I have my new one included. Thanks in advance!

If you can’tvuse different pins for shift and spi, but you have a free pin you can (I THINK) use twoo selectors connected at the free pin. When selectors are “pressed” data and time pins are connected at shift, when it isn’t the twoo pins are connected at spi.
If you haven’t free pins you can’t use shift.

But if you haven’t free pins can only be because you used everyone. So are you sure that electrically the sistem works?

I have not ordered the pcb with the shift register on it (separate board).

Could I use a spi port extender? I have searched on google, but all of them are IO, but I only need output pins. Could I just leave the MISO port of an IO extender unconnected and only use the MOSI to get outputs? I don't have a spare pin on my esp8266. Even the tx and rx ports are used as outputs. The board works perfectly, but only without the shift register.

Is there a function in the arduino language to "reset" a pin's function? So in my shift-out function, I just set the pins to output, shift the data, and then reset the pin back to function as SPI pins? That would also solve my problem.

Thanks in advance!

Rens

So you have no free pins? If so I think it's impossibke to add a port expander, and I also think that Arduino can't give eniuth electricity for your compinents.

Yeah, all the pins are used. The only "free", broken-out pin is the shift register CS. The ESP8266 powers 1 to 3 ds18b20's, and a relay via a transistor. The shift register is used to switch more relays, solenoids, etc, etc. The dc input is a 2A 3.3v transformer. The relays, solenoids etc. uses a 12v 10A transformer. I tested everything and it works electrotechnically. Now I just need to know if I can use the shift register, and HOW I can use that shift register.

Shirt registrar nweds pins to be controlled. If you don't have free pins you CAN'T use a shift register. You can OR buy a bigger Arduino OR transfer some devices ona shift register.

I don't think you understand. I have enough free pins for the shift register, but it uses the same lines as SPI. The question is: can I use the SPI lines as io's, too.

What does it means that it uses the same pins of spi? Can’t you attack it to other pins?
If the problem is software you can use a selector connected to the spi pins and controlled by a free pin. You move the selector between spi things and shift register.
But if the problem is hardware you can’t use it.

I can't attach it to other pins because I've already made the pcb. It's not really an hardware question, but a programming question.

I don't think you understand. I have enough free pins for the shift register, but it uses the same lines as SPI. The question is: can I use the SPI lines as io's, too.

Yes, they can. The question is if they are compatible. So if there is traffic on the SPI bus will that disturb the shift register? Or if there is data shifted out will the SPI bus slaves notice that?

The SPI bus is the easiest part. If CS is HIGH the SPI slave has to ignore the bus signals. This should be the case according to your "schematics".
Given there is traffic on the SPI bus, what happens to the shift register. As there is no clock signal the MOSI data on SER should be ignored. the clock on RCLK is a bad choice but copying the serial buffer to the output buffer several times should not change anything as there is no new input.

So if you clever implement the software you might get a working system with that hardware although I definitely would order new PCBs with that hardware fixed.