Skip to content
Snippets Groups Projects
Select Git revision
  • ed9c0185d80514670244b0c2147958dea00159a9
  • master default protected
2 results

pyb.SPI.rst

Blame
  • user avatar
    Damien George authored
    By virtue of its name, the pyb module would only be available on a pyboard
    and so does not need to have conditional "only" directives throughout its
    documentation.
    
    These conditionals were added mostly in
    cfcf47c0 in the initial development of the
    cc3200 port, which had the pyb module before it switched to the machine
    module.  And wipy only conditionals were removed from the pyb module
    documentation in 45426430, so there's no
    need to retain any more conditionals.
    805fd0cf
    History
    pyb.SPI.rst 4.47 KiB

    class SPI -- a master-driven serial protocol

    SPI is a serial protocol that is driven by a master. At the physical level there are 3 lines: SCK, MOSI, MISO.

    See usage model of I2C; SPI is very similar. Main difference is parameters to init the SPI bus:

    from pyb import SPI
    spi = SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0, crc=0x7)

    Only required parameter is mode, SPI.MASTER or SPI.SLAVE. Polarity can be 0 or 1, and is the level the idle clock line sits at. Phase can be 0 or 1 to sample data on the first or second clock edge respectively. Crc can be None for no CRC, or a polynomial specifier.

    Additional methods for SPI:

    data = spi.send_recv(b'1234')        # send 4 bytes and receive 4 bytes
    buf = bytearray(4)
    spi.send_recv(b'1234', buf)          # send 4 bytes and receive 4 into buf
    spi.send_recv(buf, buf)              # send/recv 4 bytes from/to buf

    Constructors

    Methods

    Constants