Skip to content

Bitbang SPI phase=1 lowest bit is wrong #20

Closed
@gingle

Description

@gingle

CircuitPython version

Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit QT Py M0 with samd21e18 also
Adafruit CircuitPython 7.0.0-beta.0-161-g65753a1c2 on 2021-09-01; with samd51j19

Code/REPL

# 09/03/2021
# looses both least significant bits
# tested on QT Py and Metro_M4_Express

import board
import digitalio
import adafruit_bitbangio as bitbangio


nEN = digitalio.DigitalInOut(board.A1)    
nEN.direction = digitalio.Direction.OUTPUT

spi = bitbangio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

def TestSPI():  
    select = nEN
    select.value = True
    while not spi.try_lock():
        pass
    spi.configure(baudrate=100000, polarity=0, phase=1, bits=8 )
    bytes_read = bytearray(4)
    select.value = False
    bytes_read = bytearray([0x33])  # changes 0x33 to 0x32 
    spi.write(bytes_read)
    bytes_read = bytearray([0x0b])  # changes 0x0b to 0x0a
    spi.write(bytes_read)
    select.value = True
    spi.unlock()

Behavior

image

Description

No response

Additional information

This works correctly:
from adafruit_bus_device.spi_device import SPIDevice

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions