We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

SPI : changing CS pin



  • Has anyone succeeded in changing the pins used for SPI from the default (MISO = 9; MOSI = 8; CLK = 7; CS1 = 6). I'm mainly interested in changing the CS1 pin setting. I have multiple SPI devices and I want to disable/enable to select one at a time.

    The SPI devices I am using are active-low enable. I am using an Omega 2+.

    Here's the setup code I'm using (python):

    # GPIO.output(pinNumber=6, setting=GPIO.HIGH)
    # GPIO.output(pinNumber=18, setting=GPIO.LOW)
    
    ...
    LSBFIRST = 1
    
    busNumber = 1
    deviceId = 32766
    ...
    self.device = onionSpi.OnionSpi(busNumber, deviceId)
    ...
    spi.sck =  7
    spi.mosi = 8
    spi.miso = 9
    spi.cs = 18
    # spi.noCs = 1
    # spi.csHigh = self.csHigh
    self.set_bit_order(LSBFIRST)
    
    # check the device
    if spi.checkDevice() is 0:
                mapped = "the device adapter is already mapped."
    else:
                mapped = "the device adapter is NOT mapped."
    print("Registered: {}".format(mapped))
    
    # register the device
    if spi.registerDevice() is 0:
                success = "Device with the specified bus number and device ID is already registered OR successfully registered SPI device adapter."
    else:
                success = "Unable to register device."
    print("Registering.. : {}".format(success))
    
    # initialize the device parameters
    if spi.setupDevice() is 0:
                success = "Setup successful."
    else:
                success = "Setup failed."
    
    print("Setting up spi device: {}".format(success))
    
    # check the device again
    if spi.checkDevice() is 0:
                mapped = "the device adapter is already mapped."
    else:
                mapped = "the device adapter is NOT mapped."
    print("Registered: {}".format(mapped))
    
    ### Here I print out all the parameters of the OnionSpi object 
    

    What I am seeing:

    • pin6 is always high (though the SPI device is read fine using the above setup code).
    • when manually changing GPIO value using something like the commented code at top : GPIO 18 switches low-to-high or high-to-low correctly, but when setting pin 18 as CS pin, nothing happens (no value change, ever). [the manual change of pin18 in conjunction with the noCS option commented out in above code]
    • Setting the csHigh value to one (in commented code) doesn't seem to have any effect whether cs pin is set to 6 or 18
    • I have confirmed that the SPI variables regurgitated after registration match the changes (pin 18 set to cs). See below.
    Registered: the device adapter is already mapped.
    > SPI device already available
    Registering.. : Device with the specified bus number and device ID is already registered OR successfully                         registered SPI device adapter.
    > Initializing SPI parameters...
      > Set SPI mode:       0x508
      > Set bits per word:  0
      > Set max speed:      100000 Hz (100 KHz)
    Setting up spi device: Setup successful.
    Registered: the device adapter is already mapped.
    ----------------
    SPI Device Settings:
      bus:    1
      device: 32766
      speed:    100000 Hz (100 kHz)
      delay:    0 us
      bpw:      8
      mode:     0 (0x08)
         3wire:    0
         lsb:      1
         loop:     0
         no-cs:    0
         cs-high:  0
    
    GPIO Settings:
      sck:      7
      mosi:     8
      miso:     9
      cs:       18 
    
    ----------------
    

    Any hints on how to debug this would be greatly appreciated. Thanks!

    Related links:
    Communicating with SPI devices
    SPI Python module



  • Hello Allison,
    Were you able to connect more SPI devices? Could you share your experiences? I am asking you because I am planning to connect 3-4 SPI devices with high sampling rate (>40kHz) and I will need to use other GPIO to do it in parallel šŸ™‚



  • Was this resolved? I am planning to have 4-5 devices on SPI and will need to be able to set up different CS lines.



  • @Jeremy-Shubert I am still fighting with it... have you been able to communicate with at least one device? I am having issues to read the bytes...



Looks like your connection to Community was lost, please wait while we try to reconnect.