@@ -470,6 +470,11 @@ def write(self, data):
470
470
"""Half-duplex SPI write. The specified array of bytes will be clocked
471
471
out the MOSI line.
472
472
"""
473
+ #check for hardware limit of FT232H and similar MPSSE chips
474
+ if (len (data ) > 65536 ):
475
+ print 'the FTDI chip is limited to 65536 bytes (64 KB) of input/output per command!'
476
+ print 'use for loops for larger reads'
477
+ exit (1 )
473
478
# Build command to write SPI data.
474
479
command = 0x10 | (self .lsbfirst << 3 ) | self .write_clock_ve
475
480
logger .debug ('SPI write with command {0:2X}.' .format (command ))
@@ -490,21 +495,31 @@ def read(self, length):
490
495
"""Half-duplex SPI read. The specified length of bytes will be clocked
491
496
in the MISO line and returned as a bytearray object.
492
497
"""
498
+ #check for hardware limit of FT232H and similar MPSSE chips
499
+ if (1 > length > 65536 ):
500
+ print 'the FTDI chip is limited to 65536 bytes (64 KB) of input/output per command!'
501
+ print 'use for loops for larger reads'
502
+ exit (1 )
493
503
# Build command to read SPI data.
494
504
command = 0x20 | (self .lsbfirst << 3 ) | (self .read_clock_ve << 2 )
495
505
logger .debug ('SPI read with command {0:2X}.' .format (command ))
496
506
# Compute length low and high bytes.
497
507
# NOTE: Must actually send length minus one because the MPSSE engine
498
508
# considers 0 a length of 1 and FFFF a length of 65536
509
+ length = length / 2
499
510
len_low = (length - 1 ) & 0xFF
500
511
len_high = ((length - 1 ) >> 8 ) & 0xFF
501
512
self ._assert_cs ()
502
513
# Send command and length.
503
- self ._ft232h ._write (str (bytearray ((command , len_low , len_high , 0x87 ))))
514
+ # Perform twice to prevent error from hardware defect/limits
515
+ self ._ft232h ._write (str (bytearray ((command , len_low , len_high ))))
516
+ payload1 = self ._ft232h ._poll_read (length )
517
+ self ._ft232h ._write (str (bytearray ((command , len_low , len_high ))))
518
+ payload2 = self ._ft232h ._poll_read (length )
504
519
self ._deassert_cs ()
505
520
# Read response bytes.
506
- return bytearray (self . _ft232h . _poll_read ( length ) )
507
-
521
+ return bytearray (payload1 + payload2 )
522
+
508
523
def bulkread (self , data = [], lengthR = 'None' , readmode = 1 ):
509
524
"""Half-duplex SPI write then read. Send command and payload to slave as bytearray
510
525
then consequently read out response from the slave for length in bytes.
@@ -548,30 +563,42 @@ def bulkread(self, data = [], lengthR = 'None', readmode = 1):
548
563
payload2 = spi ._ft232h ._poll_read (lengthR )
549
564
#end command set
550
565
spi ._deassert_cs ()
566
+ # Read response bytes.
551
567
return bytearray (payload1 + payload2 )
552
568
553
569
def transfer (self , data ):
554
570
"""Full-duplex SPI read and write. The specified array of bytes will be
555
571
clocked out the MOSI line, while simultaneously bytes will be read from
556
572
the MISO line. Read bytes will be returned as a bytearray object.
557
573
"""
574
+ #check for hardware limit of FT232H and similar MPSSE chips
575
+ if (len (data ) > 65536 ):
576
+ print 'the FTDI chip is limited to 65536 bytes (64 KB) of input/output per command!'
577
+ print 'use for loops for larger reads'
578
+ exit (1 )
558
579
# Build command to read and write SPI data.
559
580
command = 0x30 | (self .lsbfirst << 3 ) | (self .read_clock_ve << 2 ) | self .write_clock_ve
560
581
logger .debug ('SPI transfer with command {0:2X}.' .format (command ))
561
582
# Compute length low and high bytes.
562
583
# NOTE: Must actually send length minus one because the MPSSE engine
563
584
# considers 0 a length of 1 and FFFF a length of 65536
564
585
length = len (data )
586
+ length = length / 2
565
587
len_low = (length - 1 ) & 0xFF
566
588
len_high = ((length - 1 ) >> 8 ) & 0xFF
567
589
# Send command and length.
590
+ # Perform twice to prevent error from hardware defect/limits
568
591
self ._assert_cs ()
569
592
self ._ft232h ._write (str (bytearray ((command , len_low , len_high ))))
570
593
self ._ft232h ._write (str (bytearray (data )))
571
- self ._ft232h ._write ('\x87 ' )
594
+ payload1 = self ._ft232h ._poll_read (length )
595
+ self ._ft232h ._write (str (bytearray ((command , len_low , len_high ))))
596
+ self ._ft232h ._write (str (bytearray (data )))
597
+ payload2 = self ._ft232h ._poll_read (length )
598
+ #self._ft232h._write('\x87')
572
599
self ._deassert_cs ()
573
600
# Read response bytes.
574
- return bytearray (self . _ft232h . _poll_read ( length ) )
601
+ return bytearray (payload1 + payload2 )
575
602
576
603
577
604
class I2CDevice (object ):
0 commit comments