Advertisement
bRitch022

SPI1 multiple CS issue

Sep 17th, 2019
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. DI1 = MCP23S17.MCP23S17(1, 0, 1000000, "P9_27")
  2. value1 = DI1.readAll()
  3. print "Pre-DI1: ", value1
  4. #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]
  5.  
  6. DI2 = MCP23S17.MCP23S17(1, 1, 1000000, "P9_27")
  7. value2 = DI2.readAll()
  8. print "Pre-DI2: ", value2
  9. #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]
  10.  
  11. # **** This is where the error is happening ****
  12. value1 = DI1.readAll()
  13. print "Post-DI1: ", value1
  14. #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]
  15.  
  16. value2 = DI2.readAll()
  17. print "Post-DI2: ", value2
  18. #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]
  19.  
  20. class MCP23S17(object):
  21.     """MCP23S17 I/O Expander"""
  22.    
  23.     def __init__(self, bus, device, speed, reset_pin):
  24.         """Initialize the MCP Expander"""            
  25.        
  26.         self.bus = bus
  27.         self.device = device
  28.         self.reset_pin = reset_pin
  29.         self.speed = speed
  30.        
  31.         self._device = SPI(self.bus, self.device)
  32.         self._device.open(self.bus, self.device)
  33.         self.reset()
  34.        
  35.         # Set up attributes
  36.         self._device.cshigh = False  # active Low cs
  37.         self._device.lsbfirst = False  # MSB first
  38.         self._device.mode = 0b00  # mode [CPOL|CPHA]
  39.         self._device.msh = self.speed  # speed
  40.         self._device.threewire = False  # SI/SO signals are not shared
  41.         self._device.loop = False # Not in a loopback configuration
  42.        
  43.         self.setup_chip()
  44.  
  45. def setup_chip(self, IOCON_CONFIG=IOCON_CONFIG):
  46.         """Set up the IOCONFIG Register"""
  47.         self.writeU8(IOCON, IOCON_CONFIG)
  48.  
  49. def readAll(self):
  50.         """Read all registers"""
  51.         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])
  52.         return values
  53.  
  54. #Configure IOCON here:
  55. IOCON_CONFIG = 0b00000000
  56. #IOCON_CONFIG |= BANK_1       # If using this feature, define bank = 1
  57. IOCON_CONFIG |= MIRROR_ON
  58. #IOCON_CONFIG |= SEQOP_DISABLE
  59. IOCON_CONFIG |= DISSLW_DISABLE
  60. #IOCON_CONFIG |= HAEN         # Uncomment to enable hardware addressable
  61. #IOCON_CONFIG |= ODR
  62. IOCON_CONFIG |= INTPOL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement