コード例 #1
0
ファイル: spi_example.py プロジェクト: jaseg/pyBusPirateLite
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example of SPI data transfer

from pyBusPirateLite.SPI import *

spi = SPI()
spi.pins = PIN_POWER | PIN_CS
spi.config = CFG_PUSH_PULL
spi.speed = '1MHz'

# send two bytes and receive answer
spi.cs = True
data = spi.transfer([0x82, 0x55])
spi.cs = False
spi.pins = PIN_CS  # turn off power
コード例 #2
0
from pyBusPirateLite.SPI import *

BB = BBIO_base()
BB.connect()
BB.enter()

spi = SPI()
spi.pins = PIN_POWER | PIN_CS
spi.config = CFG_PUSH_PULL | CFG_CLK_EDGE
spi.speed = '30kHz'

# Read Byte. Address Passed is MSB First


def Read(address, rx_bytes):
    data = bytes()
    spi.cs = True
    spi.transfer([0x03, address[0], address[1], address[2]])
    for i in range(rx_bytes):
        data += spi.transfer([0xFF])
    spi.cs = False
    return data


# Fast Read.


def Fast_Read(address, rx_bytes):
    data = bytes()
    spi.cs = True
    spi.transfer([0x0B, address[0], address[1], address[2], 0xFF])