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

I want to use spi0 and spi1 at the same time

Discussion in 'Programming/Internet' started by 사이버, Oct 8, 2018.

  1. 사이버

    사이버 Guest

    I want to use LCD and mcp3208 simultaneously.

    spi0(gpio8,9,10,11) is port for LCD and spi1(gpio16,19,20,21) is port for mcp3208.

    spi0 channel is always on and spi1 is opened when I want to collect data.

    Question:

    1) when I checked spidev, there are spidev0.0, 0.1 but spidev1.0,1.1. Should I make spidev1.0 and 1,1? If then, How can I make them??

    2) Someone said using PIGPIO. so, I installed pigpio is raspberry pi3. My example code is like below.

    import pigpio
    import RPi.GPIO as GPIO

    pi = pigpio.pi()

    if not pi.connected:
    exit(0)

    # pi.spi_open(0, 1000000, 0) # CE0, 1Mbps, main SPI
    # pi.spi_open(0, 1000000, PI_SPI_FLAGS_AUX_SPI(1)) # CE0, 1Mbps, auxiliary SPI

    lcd=pi.spi_open(0, 1000000, 0) # CE0, main SPI
    pi.spi_read(lcd, 2)

    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    subprocess.call('setterm -cursor off', shell=True)
    subprocess.call('spincl -ib', shell=True)
    # pins connected from the SPI port on the ADC to the RPi
    SPICLK = 11
    SPIMISO = 9
    SPIMOSI = 10
    SPICS = 8

    # set up the SPI interface pins

    GPIO.setup(SPIMOSI, GPIO.OUT)
    GPIO.setup(SPIMISO, GPIO.IN )
    GPIO.setup(SPICLK, GPIO.OUT)
    GPIO.setup(SPICS, GPIO.OUT)

    # pin connected to read
    sensor_adc0 = 0;
    sensor_adc1 = 1;
    sensor_adc2 = 2;
    sensor_adc3 = 3;
    sensor_adc4 = 4;
    sensor_adc5 = 5;
    sensor_adc6 = 6;
    sensor_adc7 = 7;
    subprocess.call('clear', shell=True)

    def readadc(adcnum, clockpin, mosipin, misopin, cspin):
    mcp = pi.spi_open(0, 1000000, PI_SPI_FLAGS_AUX_SPI(1))
    pi.spi_read(mcp, 1)
    if ((adcnum > 7) or (adcnum < 0)):
    return -1
    GPIo_Output(cspin , True)

    GPIo_Output(clockpin, False) # start clock low
    GPIo_Output(cspin , False) # bring CS low

    commandout = adcnum
    commandout |= 0x18 # start bit + single-ended bit
    commandout <<= 3 # we only need to send 5 bits here
    for i in range(5):
    if (commandout & 0x80):
    GPIo_Output(mosipin, True )
    else:
    GPIo_Output(mosipin, False)
    commandout <<= 1
    GPIo_Output(clockpin, True )
    GPIo_Output(clockpin, False)

    adcout = 0

    # read in one empty bit, one null bit and 12 ADC bits
    for i in range(14):
    GPIo_Output(clockpin, True )
    GPIo_Output(clockpin, False)
    adcout <<= 1
    if (GPIO.input(misopin)):
    adcout |= 0x1

    GPIo_Output(cspin, True)

    adcout >>= 1 # first bit is 'null' so drop it
    pi.spi_close(mcp)
    return adcout

    if __name__ == '__main__':
    sensor0 = readadc(sensor_adc0, SPICLK, SPIMOSI, SPIMISO, SPICS)
    print sensor0


    It didn't work.

    How can I fix it??

    Thank you for your help.

    Login To add answer/comment
     

Share This Page