Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DI1 = MCP23S17.MCP23S17(1, 0, 1000000, "P9_27")
- value1 = DI1.readAll()
- print "Pre-DI1: ", value1
- #OUTPUT: Pre-DI1: [255, 255, 255, 0, 254, 0, 255, 0, 0, 0, 255, 0, 82, 82, 254, 0, 1, 0, 1, 0, 1, 0, 0, 0]
- DI2 = MCP23S17.MCP23S17(1, 1, 1000000, "P9_27")
- value2 = DI2.readAll()
- print "Pre-DI2: ", value2
- #OUTPUT: Pre-DI2: [255, 255, 255, 0, 254, 0, 255, 0, 0, 0, 255, 0, 82, 82, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- # **** This is where the error is happening ****
- value1 = DI1.readAll()
- print "Post-DI1: ", value1
- #OUTPUT: Post-DI1: [255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0]
- value2 = DI2.readAll()
- print "Post-DI2: ", value2
- #OUTPUT: Post-DI2: [255, 255, 255, 0, 254, 0, 255, 0, 0, 0, 255, 0, 82, 82, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0]
- class MCP23S17(object):
- """MCP23S17 I/O Expander"""
- def __init__(self, bus, device, speed, reset_pin):
- """Initialize the MCP Expander"""
- self.bus = bus
- self.device = device
- self.reset_pin = reset_pin
- self.speed = speed
- self._device = SPI(self.bus, self.device)
- self._device.open(self.bus, self.device)
- self.reset()
- # Set up attributes
- self._device.cshigh = False # active Low cs
- self._device.lsbfirst = False # MSB first
- self._device.mode = 0b00 # mode [CPOL|CPHA]
- self._device.msh = self.speed # speed
- self._device.threewire = False # SI/SO signals are not shared
- self._device.loop = False # Not in a loopback configuration
- self.setup_chip()
- def setup_chip(self, IOCON_CONFIG=IOCON_CONFIG):
- """Set up the IOCONFIG Register"""
- self.writeU8(IOCON, IOCON_CONFIG)
- def readAll(self):
- """Read all registers"""
- values = self._device.xfer2([OPCODER,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
- return values
- #Configure IOCON here:
- IOCON_CONFIG = 0b00000000
- #IOCON_CONFIG |= BANK_1 # If using this feature, define bank = 1
- IOCON_CONFIG |= MIRROR_ON
- #IOCON_CONFIG |= SEQOP_DISABLE
- IOCON_CONFIG |= DISSLW_DISABLE
- #IOCON_CONFIG |= HAEN # Uncomment to enable hardware addressable
- #IOCON_CONFIG |= ODR
- IOCON_CONFIG |= INTPOL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement