Using SPI on the Neo Air SPI does not work properly. The clk line is not stable low after CS goes low as you can see here.
1.jpg
1.jpg (68.13 KiB) Viewed 15166 times


Code: Select all

#!/usr/bin/env python3

import time
import spidev

MCP23S17_MANUF_CHIP_ADDRESS= 0x40
MCP23S17_CHIP_1=   0x40
MCP23S17_CHIP_2=   0x42

# Used For 16 bit mode ONLY
IODIR=           0x00
IPOL=            0x02
GPINTEN=         0x04
DEFVAL=          0x06
INTCON=          0x08
IOCON=           0x0A
GPPU=            0x0C
INTF=            0x0E
INTCAP=          0x10
GPIO=            0x12
OLAT=            0x14


spi = spidev.SpiDev()           # create spi object
spi.open(0, 0)                  # open spi port 0, device (CS) 0
# Set SPI speed and mode
spi.max_speed_hz = 200000
spi.mode = 0
#spi.cshigh = True
#spi.lsbfirst= True
#spi.bits_per_word= 8


spi.xfer2([MCP23S17_CHIP_1, IOCON, 0x0c, 0x0c])
spi.xfer2([MCP23S17_CHIP_1, IODIR, 0x00, 0x00])
spi.xfer2([MCP23S17_CHIP_1, GPPU,  0x00, 0x00])
spi.xfer2([MCP23S17_CHIP_1, IPOL, 0x00, 0x00])
spi.xfer2([MCP23S17_CHIP_1, GPINTEN, 0x00, 0x00])

spi.xfer2([MCP23S17_CHIP_2, IOCON, 0x0c, 0x0c])
spi.xfer2([MCP23S17_CHIP_2, IODIR, 0x00, 0x00])
spi.xfer2([MCP23S17_CHIP_2, GPPU,  0x00, 0x00])
spi.xfer2([MCP23S17_CHIP_2, IPOL, 0x00, 0x00])
spi.xfer2([MCP23S17_CHIP_2, GPINTEN, 0x00, 0x00])

spi.xfer2([MCP23S17_CHIP_1, OLAT, 0x00, 0x00])
spi.xfer2([MCP23S17_CHIP_2, OLAT, 0x00, 0x00])

try:
    while True:
        spi.xfer2([MCP23S17_CHIP_1, OLAT, 0xff, 0xff])
        spi.xfer2([MCP23S17_CHIP_2, OLAT, 0x00, 0x00])

        time.sleep(0.3)         # sleep for 0.1 seconds

        spi.xfer2([MCP23S17_CHIP_1, OLAT, 0x00, 0x00])
        spi.xfer2([MCP23S17_CHIP_2, OLAT, 0xff, 0xff])

        time.sleep(0.3)         # sleep for 0.1 seconds
except KeyboardInterrupt:       # If Ctrl+C is pressed,
    spi.close()


Here is the scope capture running the same python code on the Neo Core2, which works fine, as can bee seen here.
2.jpg
2.jpg (63.24 KiB) Viewed 15166 times