spi_example.py 406 Bytes
Newer Older
Juergen Hasch's avatar
Juergen Hasch committed
1 2 3 4
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example of SPI data transfer

5
from pyBusPirateLite.SPI import SPI
Juergen Hasch's avatar
Juergen Hasch committed
6 7 8 9 10
from pyBusPirateLite.BBIO_base import PinCfg

spi = SPI()

spi.cfg_pins(PinCfg.POWER | PinCfg.CS )
11 12
spi.config = SPI_cfg['PUSH_PULL'] | SPI_cfg['IDLE']
spi.speed = '1MHz'
Juergen Hasch's avatar
Juergen Hasch committed
13 14

# send two bytes and receive answer
15
spi.cs = True
Juergen Hasch's avatar
Juergen Hasch committed
16
data = spi.transfer( [0x82, 0x00])
17
spi.cs = False
Juergen Hasch's avatar
Juergen Hasch committed
18 19

print(ord(data[2]))