1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

RPi + Other Software Use SPI Chip Select

Discussion in 'Hardware Support' started by ScarletStar, 2 August 2016.

  1. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    Is it possible to add another SPI Device? I would like to add a NRF24 wireless transmitter which is a SPI device. The pi has two chip select pins which are not used for some reason.
     
  2. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Are you sure it's not used by the software ?

    The hardware required is probably just 1 transistor to isolate the clock line .
     
  3. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    So all I need is a 10k pull up resistor to SCLK and a PNP transistor to disconnect the LED strip when CS* is pulled high like WP_20160803_12_50_48_Pro_LI.jpg ?
     
  4. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    That sort of thing - pnp transistors make my head hurt - I always feel the need to stand on my head.

    You definitely need a resistor on the base - maybe 1k

    And standing on my head says your pull up resistor should be pull down
     
  5. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Btw - what is your led strip ?
     
  6. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    It's a WS2801.
    After looking though the inventory of a local store I will probably use a IRLML6401 MOSFET
    Would a gate resistor of 10Ohm be reasonable?
    And you're right, it has to be a pull down resistor.
     

    Attached Files:

  7. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    I don't think a mosfet needs a gate resistor - they're voltage controlled aren't they ?

    I wouldn't run this very fast - the switch off and fall time seem quite slow
     
  8. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    Isn't it more to dampen the ringing that might occur because of the resonator that's made up of the gate capacity and the wiring inductivity? Probably doesn't really matter in this case, you're right.

    Thanks. I'll try this and post back with the results.
     
  9. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    I've done some playing too...

    Using an N channel mosfet as a level shifter with a 10k pull-up.

    It doesn't work - the rise time is far too slow. I'll try changing it to 1k or 470 and let you know how it goes
     
  10. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    1k pull-up for me works much better
     
  11. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    I've tried it and for now it doesn't work. The first LED ist erratically setting colors while the rest stays dark.
    When I set it to clear in hypercon. It switches off the first led after a delay of several seconds. When I set a certain color it cycles through all sorts of colors. So it's obviously communicating. I don't have an oscilloscope to really look into the signal unfortunately.

    I'm using a 1k pull down. Using the CE1 pin on the raspberry. The other spi device on CE0 is not wired up yet.
    When setting spidev0.0 in the config, all LEDs stay dark. So that part seems to work.

    I've set the baudrate to 122000. So a clock cycle should be around 8ms.

    The datasheet of the transistor states a Turn-On Delay Time of 11ns and a 250ns Turn-Off Delay Time
    Also a rise time of 32 ns and fall time of 210ns.


    Any thoughts what might be the issue?
     
  12. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Won't it be 8 uSec ?

    Did you use a gate resistor ? I didn't.
    If you did, that will form an RC network and slowly down too.

    Triple checked the pinout and your writing ?
     
  13. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    Yes I have.
    Could it be the little extra voltage drop by R_DS(on)?
    As the WS2801 is not really rated for operation at 3.3V. It worked without the Transistor, but that might have just been the little extra drop for it to not work anymore?
     
  14. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Do you have some 74hctxx chips lying around ?

    You could use some of them as a gated level shifter.

    I used a 74hct138 as a level shifter and tied it's 3 enable lines high and low to force it on but could just as easily connected one of them to CE0 or 1
     
  15. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
  16. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    At 3.3v vcc yes

    If you want to also benefit from a reliable level shifter you really need the "T"

    The ahc/hoc have cmos level inputs and the threshold for "1" is 0.7xVCC = 3.5v and this is higher than the 3,3v gpio outputs.

    The "T" variants are TTL compatible and have the threshold at about 2v

    If you have a non "T" on hand, power it from 5v but use a diode to drop it to about 4.3v vcc.
    This gives you a "1" threshold of 0.7x4.3 = 3.01v
     
  17. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Oh and don't forget a pull-up on the data lines to the strip cos when the 125 is not enabled the outputs will be open/floating and will pick up noise.
     
  18. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    Thanks for the heads up. I'll go get one :)
     
  19. ScarletStar

    ScarletStar New Member

    Messages:
    13
    Hardware:
    RPi1/Zero, +Arduino, +PhilipsHue
    Finally got around to it. And good news it seems to work. So it seems like the 3.3V were in fact the problem.

    At least without the other SPI channel being used.
    I'll report back once I get that NRF24 chip working for a final conclusive green light.

    Thanks a lot for the suggestion with the 74HCT :)
     
  20. penfold42

    penfold42 Active Member

    Messages:
    746
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Excellent !