SPIDevice selects an active-high device as soon as it is created
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 73/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from adafruit/circuitpython
-
documentation rp2
Difficulty 1/5 1-3 hours Newbie friendliness 67/100
adafruit/circuitpython#11779 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
adafruit/circuitpython#11689 ·
Maintainers usually reply within 1 day
-
enhancement network
Difficulty 4/5 3-5 days Newbie friendliness 48/100
adafruit/circuitpython#11845 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 5/5 Over a week Newbie friendliness 25/100
adafruit/circuitpython#11834 ·
Maintainers usually reply within 1 day
-
audio bug crash esp32-s3 needs retest
Difficulty 4/5 3-5 days Newbie friendliness 45/100
adafruit/circuitpython#11822 · 2 comments ·
Maintainers usually reply within 1 day
All issues in adafruit/circuitpython
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
gnif/LookingGlass#1352 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
bazel-contrib/rules_go#4784 · 1 comment ·
Maintainers usually reply within 1 day
-
Bug: settings::init() silently continues when neutralino.config.json is missingPossibly taken @mishradwaterlaw claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
neutralinojs/neutralinojs#1882 ·
Maintainers usually reply within 1 day