NRF24L01+ on SPI1, TFT on SPI0



  • Hello guys,

    MySensors + Openhab + Serial = DONE and I can almost do it with my eyes closed now hahaha thanks to the forums!

    however I need to use the SPI1 for the NRF24L01 and leave the main SPI for a Touch Display (MHS Series 3.5" from KUMAN>Amazon)

    I have got it to work, after battling it a little bit, and for some reason it disables SPI when you load the damn thing 😕

    https://github.com/goodtft/LCD-show.git

    sudo ./MHS35-show
    

    but I was able to re-enable the SPI by de-compiling the overlay file "mhs35.dtbo" enable SPI then compile again..

    ls /dev/ gives me the following

    autofs           fuse       loop1             mqueue              ram14    serial1    tty14  tty27  tty4   tty52  tty8       vcs2   vcsm
    block            gpiochip0  loop2             net                 ram15    shm        tty15  tty28  tty40  tty53  tty9       vcs3   vhci
    btrfs-control    gpiochip1  loop3             network_latency     ram2     snd        tty16  tty29  tty41  tty54  ttyAMA0    vcs4   watchdog
    bus              gpiochip2  loop4             network_throughput  ram3     spidev1.0  tty17  tty3   tty42  tty55  ttyprintk  vcs5   watchdog0
    cachefiles       gpiomem    loop5             null                ram4     stderr     tty18  tty30  tty43  tty56  ttyS0      vcs6   zero
    char             hidraw0    loop6             ppp                 ram5     stdin      tty19  tty31  tty44  tty57  uhid       vcs7
    console          hidraw1    loop7             ptmx                ram6     stdout     tty2   tty32  tty45  tty58  uinput     vcsa
    cpu_dma_latency  hwrng      loop-control      pts                 ram7     tty        tty20  tty33  tty46  tty59  urandom    vcsa1
    cuse             i2c-1      mapper            ram0                ram8     tty0       tty21  tty34  tty47  tty6   usb        vcsa2
    disk             initctl    mem               ram1                ram9     tty1       tty22  tty35  tty48  tty60  vchiq      vcsa3
    fb0              input      memory_bandwidth  ram10               random   tty10      tty23  tty36  tty49  tty61  vcio       vcsa4
    fb1              kmsg       mmcblk0           ram11               raw      tty11      tty24  tty37  tty5   tty62  vc-mem     vcsa5
    fd               log        mmcblk0p1         ram12               rfkill   tty12      tty25  tty38  tty50  tty63  vcs        vcsa6
    full             loop0      mmcblk0p2         ram13               serial0  tty13      tty26  tty39  tty51  tty7   vcs1       vcsa7
    

    I do see "spidev1.0" which is a good thing, however I don't see "tty/USB0" like I used to when installing MySensors 😕

    Tutorials I followed :
    Double SPI Radio Raspberry Pi
    OpenHAB 2.4 MySensors Serial Gateway - How to install (only did MySensors portion)

    with the following "edited" ./configure line

    sudo ./configure --my-gateway=serial --my-debug=enable --my-signing-debug --my-serial-is-pty --my-serial-groupname=tty --my-transport=rf24 --my-rf24-channel=76 --my-rf24-ce-pin=37 --my-rf24-cs-pin=36
    
    • Getting the following from MySensors...
    pi@raspberrypi:~/MySensors $ sudo ./bin/mysgw
    Mar 10 10:51:16 INFO  Starting gateway...
    Mar 10 10:51:16 INFO  Protocol version - 2.3.1
    Mar 10 10:51:16 DEBUG Serial port /dev/ttyUSB0 (115200 baud) created
    Mar 10 10:51:16 DEBUG MCO:BGN:INIT GW,CP=RNNGL---,REL=255,VER=2.3.1
    Mar 10 10:51:16 DEBUG TSF:LRT:OK
    Mar 10 10:51:16 DEBUG TSM:INIT
    Mar 10 10:51:16 DEBUG TSF:WUR:MS=0
    Mar 10 10:51:16 DEBUG !TSM:INIT:TSP FAIL
    Mar 10 10:51:16 DEBUG TSM:FAIL:CNT=1
    Mar 10 10:51:16 DEBUG TSM:FAIL:DIS
    Mar 10 10:51:16 DEBUG TSF:TDI:TSL
    
    • mini-display stopped booting to desktop and the last line is:

    [ ]Starting Load/Save RF Kill Switch Status

    Any suggestions to where I can start? don't I need to define which pins are used for MISO, MOSI & CLK? I am using the "alternate" pins described as per the picture on MySensors:
    alt text


  • Mod

    @nizoo91 I think you need to add spi-spidev-device=<DEVICE> to the configure command



  • @mfalkvidd Thank you for that, however I am still having issues trying to run the NRF24 from SPI1, I tried replacing the NRF24 as well but still didn't work 😕

    Ls /dev/ shows: spidev1.0

    This is what I added to /boot/config.txt
    Because the default is GPIO 18 (Pin12) which is being used by the TFT.

    # Enable audio (loads snd_bcm2835) (the below is added by the TFT setup)
    dtparam=audio=on
    dtoverlay=mhs35
    hdmi_force_hotplug=1
    hdmi_group=2
    hdmi_mode=1
    hdmi_mode=87
    hdmi_cvt 480 320 60 6 0 0 0
    hdmi_drive=2
    
    
    #below are things I added: 
    #disable bluetooth, not sure why I did this.. 
    dtoverlay=pi3-disable-bt
    
    #enabled spi1 with 1cs pin (default is BCM18, therefor I moved it to BCM 5 / PIN 29)
    dtoverlay=spi1-1cs,cs0_pin=5
    

    This is the line I am using now:

    sudo ./configure --my-gateway=serial --my-debug=enable --my-serial-is-pty --my-serial-groupname=tty --my-transport=rf24 --my-rf24-channel=76 --my-rf24-ce-pin=37 --my-rf24-cs-pin=29 --spi-spidev-device=/dev/spidev1.0
    
    [SECTION] Detecting target machine.
      [OK] machine detected: SoC=BCM2837, Type=rpi3, CPU=armv7l.
    [SECTION] Detecting SPI driver.
      [OK] SPI driver detected:BCM.
    [SECTION] Gateway configuration.
      [OK] Type: serial.
      [OK] Transport: rf24.
      [OK] Signing: Disabled.
      [OK] Encryption: Disabled.
      [OK] CPPFLAGS: -DMY_RADIO_RF24 -DMY_GATEWAY_SERIAL -DMY_DEBUG -DLINUX_SPI_BCM -DLINUX_ARCH_RASPBERRYPI -DSPI_SPIDEV_DEVICE="/dev/spidev1.0" -DMY_RF24_CS_PIN=29 -DMY_RF24_CE_PIN=37 -DMY_RF24_CHANNEL=76 -DMY_LINUX_SERIAL_GROUPNAME="tty" -DMY_LINUX_SERIAL_IS_PTY
    [SECTION] Detecting init system.
      [OK] Init system detected: systemd.
    [SECTION] Saving configuration.
      [OK] Saved.
    [SECTION] Cleaning previous builds.
      [OK] Finished.
    
    • Getting the following after installing:
    pi@raspberrypi:~/MySensors $ sudo ./bin/mysgw
    Mar 11 04:11:02 INFO  Starting gateway...
    Mar 11 04:11:02 INFO  Protocol version - 2.3.1
    Mar 11 04:11:02 DEBUG Serial port /dev/ttyUSB0 (115200 baud) created
    Mar 11 04:11:02 DEBUG MCO:BGN:INIT GW,CP=RNNGL---,REL=255,VER=2.3.1
    Mar 11 04:11:02 DEBUG TSF:LRT:OK
    Mar 11 04:11:02 DEBUG TSM:INIT
    Mar 11 04:11:02 DEBUG TSF:WUR:MS=0
    Mar 11 04:11:02 DEBUG !TSM:INIT:TSP FAIL
    Mar 11 04:11:02 DEBUG TSM:FAIL:CNT=1
    Mar 11 04:11:02 DEBUG TSM:FAIL:DIS
    Mar 11 04:11:02 DEBUG TSF:TDI:TSL
    Mar 11 04:11:12 DEBUG TSM:FAIL:RE-INIT
    Mar 11 04:11:12 DEBUG TSM:INIT
    Mar 11 04:11:12 DEBUG !TSM:INIT:TSP FAIL
    Mar 11 04:11:12 DEBUG TSM:FAIL:CNT=2
    Mar 11 04:11:12 DEBUG TSM:FAIL:DIS
    Mar 11 04:11:12 DEBUG TSF:TDI:TSL
    

    any additional suggestions?



  • For anyone interested in something similar, you have to specify the following when using ./configre..

    --spi-driver=SPIDEV
    

    I added the above and it worked like a charm!

    For some reason, my TFT disables both SPI0 & SPI1, which took me sometime to figure out on how re-enable it! once that was done, it was a piece of cake!

    complete command:

    sudo ./configure --my-gateway=serial --my-debug=enable --my-serial-is-pty --my-serial-groupname=tty --my-transport=rf24 --my-rf24-channel=76 --my-rf24-ce-pin=37 --my-rf24-cs-pin=29 --spi-spidev-device=/dev/spidev1.0 --spi-driver=SPIDEV
    


  • Was struggling yesterday with a similar setup, but another GPIOs. The widespread image:
    alt text
    that discribes RPi's GPIOs, that is also used in the tutorial at mysensors is wrong. It says that SPI1 uses pin 36 as CS but in fact it doesn't. Actually SPI1 has 3 CS(CE) pins which can be enabled in /boot/config.txt with options dtoverlay=spi1-1cs, dtoverlay=spi1-2cs or dtoverlay=spi1-3cs. These options will enable 1, 2 or 3 CS pins accordingly. The pins are: SPI1 CS0 - pin12, SPI1 CS1 - pin11, SPI1 CS2 - pin36. So to be able to use pin 36 as CS we need to use option dtoverlay=spi1-3cs, but then we are losing 2 gpio, as they are also used by SPI1. The solution to this can be found here: https://www.raspberrypi.org/forums/viewtopic.php?t=203776. We need to make custom overlay file to use only pin36 as SPI CS0. The whole procedure is well described on the mentioned page. After adding custom overlay option which maps pin36 as SPI1 CS0 everything works fine.



  • @monte said in NRF24L01+ on SPI1, TFT on SPI0:

    he pins are: SPI1 CS0

    While the link you have provided is true and it may work, (I have not tested that method) you can simply do the following which is much easier:

    //cs0_pin=5 is GPIO pin, which is PIN 29

    dtoverlay=spi1-1cs,cs0_pin=5
    

    you can basically pick whichever pin you want as long as you tell MySensors which pin you are using when you run the ./configure using:

    --my-rf24-cs-pin=29
    


  • @nizoo91 that's nice, but i didn't found this method. Thanks for the tip! It is definitely easier to do this way 🙂
    But my main point was to help someone who will try to compile mysgw for SPI1 and it won't work, because picture he refered to was wrong... I may be stupid, but i spent whole day figuring that out 🙂



  • @monte said in NRF24L01+ on SPI1, TFT on SPI0:

    @nizoo91 that's nice, but i didn't found this method. Thanks for the tip! It is definitely easier to do this way 🙂
    But my main point was to help someone who will try to compile mysgw for SPI1 and it won't work, because picture he refered to was wrong... I may be stupid, but i spent whole day figuring that out 🙂

    For sure 🙂 trust me I have been there and done that, spent days trying to figure something out and to find out it was the simplest thing to solve hahah

    Anyhow, checkout this site for any pin reference you need. I found it to be very accurate 😉

    https://pinout.xyz/pinout/spi


Log in to reply
 

Suggested Topics

  • 87
  • 6
  • 8
  • 10
  • 7
  • 7

69
Online

11.4k
Users

11.1k
Topics

112.7k
Posts