ValueError: SCK in use

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
spatialhacker
 
Posts: 7
Joined: Mon Jun 20, 2011 6:24 pm

ValueError: SCK in use

Post by spatialhacker »

Environment:
Adafruit CircuitPython 7.3.3 on 2022-08-29; Adafruit Feather ESP32-S2 TFT with ESP32S2
Board ID:adafruit_feather_esp32s2_tft

Running the code or any similar that uses busio.SPI results in
In line 5
"ValueError: SCK in use"

Code: Select all

import busio
import digitalio
from board import *
from adafruit_bus_device.spi_device import SPIDevice
with busio.SPI(SCK, MOSI, MISO) as spi_bus:
    cs = digitalio.DigitalInOut(D10)
    device = SPIDevice(spi_bus, cs)
    bytes_read = bytearray(4)
    # The object assigned to spi in the with statements below
    # is the original spi_bus object. We are using the busio.SPI
    # operations busio.SPI.readinto() and busio.SPI.write().
    with device as spi:
        spi.readinto(bytes_read)
    # A second transaction
    with device as spi:
        spi.write(bytes_read)

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: ValueError: SCK in use

Post by danhalbert »

The display uses the SPI bus, so you can't create a fresh SPI bus that uses the same pins.

But you can share the user of that bus. In your code use

Code: Select all

board.SPI()
or

Code: Select all

spi = board.SPI()
That will use the already-set-up SPI bus.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”