Skip to content

SPI.beginTransaction does not set SCK value until the first write #9221

Closed
@and3rson

Description

@and3rson

Board

ESP32-C3

Device Description

No hardware

Hardware Configuration

SCK = 0
MISO = 8
MOSI = 1

Version

latest master (checkout manually)

IDE Name

n/a

Operating System

n/a

Flash frequency

40MHz

PSRAM enabled

no

Upload speed

n/a

Description

SPI clock polarity is not affected by beginTransaction until the first write. This leads to slave device ignoring some SPI packets.

This has affected my TFT display, since clock polarity was not being changed before activating the display until the first command was sent.
The only solution was to write a dummy byte directly after beginTransaction.
Related issue: moononournation/Arduino_GFX#433

I'm not sure if this is the expected behavior, but I would certainly expect beginTransaction to immediately update SCK polarity that's appropriate for the selected SPI mode.

Sketch

    SPI.beginTransaction(SPISettings(..., ..., SPI_MODE0)); // Set SPI mode to 0 (CPOL=0)
    SPI.write(0xFF);
    SPI.endTransaction();
    // SCK is now LOW (SPI mode 0)

    SPI.beginTransaction(SPISettings(..., ..., SPI_MODE3)); // Set SPI mode to 3 (CPOL=1)
    // Problem: SCK is STILL LOW (SPI despite being in mode 3).
    // If we assert device's SS signal, it will enter incosistent state
    // due to SCK being low, effectively missing the first bit of the message.
    SPI.endTransaction();
    // SCK is still LOW...

Debug Message

n/a

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Area: Peripherals APIRelates to peripheral's APIs.Chip: ESP32-C3Issue is related to support of ESP32-C3 ChipStatus: Needs investigationWe need to do some research before taking next steps on this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions