from binascii import hexlify
from pyftdi.ftdi import Ftdi
from pyftdi.spi import SpiController
from sys import modules, stderr, stdout


# Instanciate a SPI controller
spi = SpiController()

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

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

#to get the maximun frequency possible on this link
print("Vitesse SPI max:",spi.frequency_max/1.0E6,"MHz")

jedec_id = slave.exchange([0x9f], 3).tobytes()
print(jedec_id)
Vitesse SPI max: 30.0 MHz
b'\xff\xff\xff'
import struct
#The cs shall be manual - use of I/O4
gpio = spi.get_gpio()


# IO4 = ACBUS3 -> GPIO11
#Parameters:    pins (int) – which GPIO pins should be reconfigured
#    direction (int) – a bitfield of GPIO pins. Each bit represent a GPIO pin, where a high level sets the pin as output and a low level sets the pin as input/high-Z.



print( hex( gpio.direction) )

gpio.set_direction(0x0800, 0x0100)
gpio.write(0x0100)
0x7b
#before exchange
gpio.write(0x0100)
#to send a data 
slave.write([int(0xAA)], True, True)
slave.write([int(0xEB)], True, True) 
slave.write([int(0x01)], True, True)


#after exchange
gpio.write(0x0000)
gpio.write(0x0100)


results matching ""

    No results matching ""