from binascii import hexlify
from pyftdi.ftdi import Ftdi
from pyftdi.spi import SpiController, SpiPort
from sys import modules, stderr, stdout 
from pyftdi.usbtools import UsbTools
from os import environ

# Instanciate a SPI controller
spi = SpiController(cscount =3,turbo=False)

# Configure the first interface (IF/1) of the FTDI device as a SPI master
spi.configure('ftdi://ftdi:2232h/1')
slave = spi.get_port(cs=0, freq=12E6, mode=0)

print(spi.frequency_max)

C = spi.get_gpio()
print(C)
C.read()
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-52-0954055a4492> in <module>()
      7 
      8 # Instanciate a SPI controller
----> 9 spi = SpiController(cscount =3,turbo=False)
     10 
     11 # Configure the first interface (IF/1) of the FTDI device as a SPI master


TypeError: __init__() got an unexpected keyword argument 'cscount'
url = environ.get('FTDI_DEVICE', 'ftdi://ftdi:2232h/1')
print(url)
ftdi://ftdi:2232h/1
spi = SpiController(turbo=False)
port = spi.get_port(1, freq=3E6, mode=0)
jedec_id = port.exchange([0x9f], 3).tobytes()
hex_jedec_id = hexlify(jedec_id).decode()
print('JEDEC ID:', hex_jedec_id)
spi.terminate()
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-53-04b22ab91cca> in <module>()
      1 spi = SpiController(turbo=False)
----> 2 port = spi.get_port(1, freq=3E6, mode=0)
      3 jedec_id = port.exchange([0x9f], 3).tobytes()
      4 hex_jedec_id = hexlify(jedec_id).decode()
      5 print('JEDEC ID:', hex_jedec_id)


~/.local/lib/python3.5/site-packages/pyftdi/spi.py in get_port(self, cs, freq, mode)
    320             if not self._ftdi:
    321                 raise SpiIOError("FTDI controller not initialized")
--> 322             if cs >= len(self._spi_ports):
    323                 raise SpiIOError("No such SPI port")
    324             if not (0 <= mode <= 3):


AttributeError: 'SpiController' object has no attribute '_spi_ports'
# Check presence of device

vid=0x0403
pid=0x6010

Board =  UsbTools.find_all([(vid, pid)]) 
print(vid,pid,Board) # return:
1027 24592 [(1027, 24592, None, 2, 'Dual RS232-HS')]
gpio = spi.get_gpio()
gpio.set_direction(0x30, 0x10)

# Assert GPO pin
gpio.write(0x10)
# Write to SPI slace
slave.write(b'hello world!')
# Release GPO pin
gpio.write(0x00)
---------------------------------------------------------------------------

SpiIOError                                Traceback (most recent call last)

<ipython-input-23-d7eb196e649b> in <module>()
      1 gpio = spi.get_gpio()
----> 2 gpio.set_direction(0x30, 0x10)
      3 
      4 # Assert GPO pin
      5 gpio.write(0x10)


~/.local/lib/python3.5/site-packages/pyftdi/spi.py in set_direction(self, pins, direction)
    222            :param int direction: direction bitfield (high level for output)
    223         """
--> 224         self._controller.set_gpio_direction(pins, direction)
    225 
    226 


~/.local/lib/python3.5/site-packages/pyftdi/spi.py in set_gpio_direction(self, pins, direction)
    420         with self._lock:
    421             if pins & self._spi_mask:
--> 422                 raise SpiIOError('Cannot access SPI pins as GPIO')
    423             mask = self._get_gpio_mask()
    424             if (pins & mask) != pins:


SpiIOError: Cannot access SPI pins as GPIO


[(1027, 24592, None, 2, 'Dual RS232-HS')]
import time
from pyftdi.spi import SpiController
ctrl = SpiController(cs_count=1, turbo=True)
ctrl.configure('ftdi://ftdi:2232h/1')  # Make sure you've loaded libusb-win32 using Zadig
spi = ctrl.get_port(cs=0)  # Chip select is 0 -- corresponds to D3
spi.set_frequency(3000000)

from array import array as Array
from pyftdi.ftdi import Ftdi

acbus_direction = 0x01 # Bit C0 is output for reset

ctrl._ftdi.write_data(Array('B', [Ftdi.SET_BITS_HIGH, 0x00, acbus_direction]))
time.sleep(1.0)
ctrl._ftdi.write_data(Array('B', [Ftdi.SET_BITS_HIGH, 0x01, acbus_direction]))
time.sleep(1.0)
# Instanciate a SPI controller
spi = SpiController()

# Configure the first interface (IF/1) of the first FTDI device as a
# SPI master
spi.configure('ftdi://::/1')

# Get a SPI port to a SPI slave w/ /CS on A*BUS3 and SPI mode 0 @ 12MHz
slave = spi.get_port(cs=0, freq=12E6, mode=0)

# Get GPIO port to manage extra pins, use A*BUS4 as GPO, A*BUS4 as GPI
gpio = spi.get_gpio()
#gpio.set_direction(0x30, 0x10)

# Assert GPO pin
gpio.write(0x10)
# Write to SPI slace
slave.write(b'hello world!')
# Release GPO pin
gpio.write(0x00)
# Test GPI pin
pin = bool(gpio.read() & 0x20)
---------------------------------------------------------------------------

SpiIOError                                Traceback (most recent call last)

<ipython-input-31-0d8e8d355702> in <module>()
     14 
     15 # Assert GPO pin
---> 16 gpio.write(0x10)
     17 # Write to SPI slace
     18 slave.write(b'hello world!')


~/.local/lib/python3.5/site-packages/pyftdi/spi.py in write(self, value)
    214            :param int value: the GPIO port pins as a bitfield
    215         """
--> 216         return self._controller.write_gpio(value)
    217 
    218     def set_direction(self, pins, direction):


~/.local/lib/python3.5/site-packages/pyftdi/spi.py in write_gpio(self, value)
    403             if (value & mask) != value:
    404                 raise SpiIOError('No such GPIO pins: %04x/%04x' %
--> 405                                  (mask, value))
    406             # perform read-modify-write
    407             use_high = self._wide_port and (self.direction & 0xff00)


SpiIOError: No such GPIO pins: ff80/0010
0xff80
65408


results matching ""

    No results matching ""