Skip to content

bitbangio SPI issue when CPOL=1 #9074

Closed
@kbsriram

Description

@kbsriram

CircuitPython version

Adafruit CircuitPython 9.0.0-beta.1-52-g84e937f1c4 on 2024-03-20; Raspberry Pi Pico W with rp2040

Code/REPL

import board
import bitbangio
import digitalio
import time


def doit():
    with digitalio.DigitalInOut(board.GP13) as en:
        en.switch_to_output(value=True)
        time.sleep(1)
        with bitbangio.SPI(clock=board.GP15, MOSI=board.GP14) as spi:
            spi.try_lock()
            spi.configure(baudrate=10, polarity=1, phase=0, bits=8)
            en.switch_to_output(value=False)
            spi.write(b"\xaa")
            en.switch_to_output(value=True)

Behavior

There's a missing clock transition when CPOL=1 resulting in a failed decode.

Description

This was noted elsewhere in adafruit/Adafruit_CircuitPython_BitbangIO#31 (comment) and opened as a new issue here for clarity.

p1-before

The SPI code assumes the clock starts at an idle transition, but is currently not updated if it is modified during the configure() call. So the first intended clock transition never occurs as it starts in the active state.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions