SPI bug?



  • I'm seeing some very strange behavior on the SPI inteface on a LoPy.

    The SPI class is instantiated as so:
    from machine import SPI
    spi = SPI(0, mode=SPI.MASTER, baudrate=250000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB)

    Using a very simple test loop:
    while True:
    cs(0)
    spi.write(b'\xFF')
    cs(1)

    This works as expected:
    0_1495470811126_spi-write FF.png

    In the screenshot:

    • Yellow - SPI Clock
    • Light Blue - CS line (P9 in this example, although here it's only used to trigger the o'scope)
    • Dark Blue - MISO
    • Pink - MOSI

    Note that there is nothing connected to the SPI pins (using defaults P10/11/12), except a pull-up on MISO. Also, I've tested other values in the write function, including a bytes array, and what I see on the o'scope matches what I'm writing exactly, as expected.

    But when I use this test loop:
    while True:
    cs(0)
    spi.read(1, write=0xFF)
    cs(1)

    I see this:
    0_1495471080935_spi-read FF.png

    Note that the LoPy is driving MOSI (with what appears to be 0x55). What's even more interesting is that this is the pattern I see regardless of the value supplied to the 'write' argument).

    I couldn't find the source code for the SPI class (not sure if it's published), so I wasn't able to look at the read code. Could this be a bug or am I doing something wrong?



  • Additional info...

    I'm pretty well convinced that none of the SPI functions that take a 'write' argument pay any attention to that argument--no matter what, only 0x55 is sent during the operation. So I tried rewriting my SPI driver to use only the write_readinto function, passing in a write buffer full of 0xFF. This worked as expected (and made my driver work as well--unfortunately, it makes for some pretty gross code to use only write_readinto).


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.