@@ -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,43 +495,64 @@ 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 ) )
521
+ return bytearray (payload1 + payload2 )
507
522
508
523
def transfer (self , data ):
509
524
"""Full-duplex SPI read and write. The specified array of bytes will be
510
525
clocked out the MOSI line, while simultaneously bytes will be read from
511
526
the MISO line. Read bytes will be returned as a bytearray object.
512
527
"""
528
+ #check for hardware limit of FT232H and similar MPSSE chips
529
+ if (len (data ) > 65536 ):
530
+ print 'the FTDI chip is limited to 65536 bytes (64 KB) of input/output per command!'
531
+ print 'use for loops for larger reads'
532
+ exit (1 )
513
533
# Build command to read and write SPI data.
514
534
command = 0x30 | (self .lsbfirst << 3 ) | (self .read_clock_ve << 2 ) | self .write_clock_ve
515
535
logger .debug ('SPI transfer with command {0:2X}.' .format (command ))
516
536
# Compute length low and high bytes.
517
537
# NOTE: Must actually send length minus one because the MPSSE engine
518
538
# considers 0 a length of 1 and FFFF a length of 65536
519
539
length = len (data )
540
+ length = length / 2
520
541
len_low = (length - 1 ) & 0xFF
521
542
len_high = ((length - 1 ) >> 8 ) & 0xFF
522
543
# Send command and length.
544
+ # Perform twice to prevent error from hardware defect/limits
523
545
self ._assert_cs ()
524
546
self ._ft232h ._write (str (bytearray ((command , len_low , len_high ))))
525
547
self ._ft232h ._write (str (bytearray (data )))
526
- self ._ft232h ._write ('\x87 ' )
548
+ payload1 = self ._ft232h ._poll_read (length )
549
+ self ._ft232h ._write (str (bytearray ((command , len_low , len_high ))))
550
+ self ._ft232h ._write (str (bytearray (data )))
551
+ payload2 = self ._ft232h ._poll_read (length )
552
+ #self._ft232h._write('\x87')
527
553
self ._deassert_cs ()
528
554
# Read response bytes.
529
- return bytearray (self . _ft232h . _poll_read ( length ) )
555
+ return bytearray (payload1 + payload2 )
530
556
531
557
532
558
class I2CDevice (object ):
0 commit comments