SPIDevice selects an active-high device as soon as it is created

Open Beginner friendly
#11,869 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@mikeysklar is already working on this.

Since Nov 13, 2026.

  • #11870 by @mikeysklar — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, python
Domain
embedded-iot

Research direction

Read shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c, focusing on the switch_to_output call and how it uses cs_active_value. Reproduce the supplied example and verify that construction leaves an active-high device unselected, while a transaction selects it and exiting the transaction deselects it.

Written by the indexing model from the issue text.

Description

SPIDevice() sets the chip select pin high as soon as it is created.

That is wrong for a device with cs_active_value=True: it selects the device before any transaction.

The Python BusDevice library sets the pin to not cs_active_value instead.

import board, busio, digitalio
from adafruit_bus_device.spi_device import SPIDevice

spi = busio.SPI(board.GP18, MOSI=board.GP19, MISO=board.GP16)
cs = digitalio.DigitalInOut(board.GP17)
print("fresh", cs.direction, cs.value)
d = SPIDevice(spi, cs, cs_active_value=True)
print("constructed", cs.direction, cs.value)
with d:
    print("in transaction", cs.value)
print("after transaction", cs.value)
fresh digitalio.Direction.INPUT False
constructed digitalio.Direction.OUTPUT True
in transaction True
after transaction False

constructed should be False.

Board Raspberry Pi Pico (RP2040)
Version 11.0.0-alpha.3-7-g95f9ddb95b, also seen on the desktop port
Cause shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c calls switch_to_output(..., true, ...) regardless of cs_active_value
Also on 10.3.x (same line)

Found with Claude while testing #11865; I ran the code above on the Pico myself.

Dominant language
C
Stars
4.6k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
208

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from adafruit/circuitpython

All issues in adafruit/circuitpython

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.