spi_example.py 462 Bytes
Newer Older
Juergen Hasch's avatar
Juergen Hasch committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example of SPI data transfer

from pyBusPirateLite.SPI import *
from pyBusPirateLite.BBIO_base import PinCfg

spi = SPI()
spi.connect('COM3')
spi.enter_bb()
spi.enter_spi()

spi.cfg_pins(PinCfg.POWER | PinCfg.CS )
spi.cfg_spi( 0x0c )
spi.set_speed(SPISpeed._1MHZ)

# send two bytes and receive answer
spi.cs_low()
data = spi.transfer( [0x82, 0x00])
spi.cs_high()

print(ord(data[2]))

spi.reset()
spi.port.close()