From: Dan White Date: Tue, 17 Jul 2012 02:33:32 +0000 (-0500) Subject: paranoid timing for CS, SK setting X-Git-Tag: calibrations~23 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=9f122cd1f74a1c01c13e47dc9187dd68080a8c2f;p=430.git paranoid timing for CS, SK setting Move the SK pin to the data-start state before asserting the CS pins. Then we are sure to not wiggle SK when CS is (being) asserted and (maybe) violate some timing-related error. --- diff --git a/python-lib/usbio.py b/python-lib/usbio.py index 47bf3ab..0308b55 100644 --- a/python-lib/usbio.py +++ b/python-lib/usbio.py @@ -487,17 +487,34 @@ class SPI(object): sham, mask = self.cs['_mask'] mode, pins = self.cs[device] - p = self._pinstate & ~mask - p += pins & mask + # set SK before asserting CS to not violate timing + if True: + # first, ensure SK starts in the correct state + p = self._pinstate + if mode in (0, 1): + p |= 0x01 + elif mode in (2, 3): + p &= 0xfe + cmd = chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir) + + p &= ~mask + p += pins & mask + self._pinstate = p + cmd += chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir) + # old behavior: set CS and SK in same command + else: + p = self._pinstate & ~mask + p += pins & mask - # ensure SK starts in the correct state - if mode in (0, 1): - p |= 0x01 - elif mode in (2, 3): - p &= 0xfe + # ensure SK starts in the correct state + if mode in (0, 1): + p |= 0x01 + elif mode in (2, 3): + p &= 0xfe + + self._pinstate = p + cmd = chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir) - self._pinstate = p - cmd = chr(self.ftdi.SET_BITS_LOW) + chr(p) + chr(self._pindir) return cmd def _mk_cs_cmd_cache(self):