Coder Social home page Coder Social logo

Comments (5)

earlephilhower avatar earlephilhower commented on June 12, 2024

I'm kind of confused here, sorry. Are you saying the SDK is inverted, or this core is? And if it was inverted wouldn't there be serious trouble communicating with a wide array of devices?

The logic for converting from Arduino modes to SDK modes is here:

inline spi_cpol_t SPIClassRP2040::cpol() {
switch (_spis.getDataMode()) {
case SPI_MODE0:
return SPI_CPOL_0;
case SPI_MODE1:
return SPI_CPOL_0;
case SPI_MODE2:
return SPI_CPOL_1;
case SPI_MODE3:
return SPI_CPOL_1;
}
// Error
return SPI_CPOL_0;
}
inline spi_cpha_t SPIClassRP2040::cpha() {
switch (_spis.getDataMode()) {
case SPI_MODE0:
return SPI_CPHA_0;
case SPI_MODE1:
return SPI_CPHA_1;
case SPI_MODE2:
return SPI_CPHA_0;
case SPI_MODE3:
return SPI_CPHA_1;
}
// Error
return SPI_CPHA_0;
}

Looking at those 2 switches and the Wikipedia article, the values themselves seem to be correct.

The actual values are set in beginTransaction, just as in your SDK code:

spi_init(_spi, _spis.getClockFreq());
spi_set_format(_spi, 8, cpol(), cpha(), SPI_MSB_FIRST);

from arduino-pico.

maxgerhardt avatar maxgerhardt commented on June 12, 2024

The conversion of the Arduino core / library from SPI mode to CPOL and CPHA is correct, what I'm saying is that SPI Mode 0 (equates CPOL = 0, CPHA = 0) should have a clock idling LOW (per wikipedia), but is actually idling HIGH on real hardware. It's as if the RP2040 chip has inverted SCLK idle levels for CPOL = 0 / 1.

Both the Arduino core and the Pico-SDK functions exhibit SCLK idle level = HIGH when both are correctly asked for SPI Mode 0 / CPOL=0, CPHA=0, when Wikie says it should be LOW.

from arduino-pico.

earlephilhower avatar earlephilhower commented on June 12, 2024

Ah, gotcha. Maybe this would be better handled at the Pico-SDK repo or the Raspberry Pi forum?.

Looking at the chip docs, they do show the clock low during idle for CPOL=0 (SPO=0)
image

and high during idle for CPOL=1: (SPO=1)
image

The SSPCR0 register has the 2 bits for CPOL/CPHA, and I see nothing else related to clock polarity elsewhere.

from arduino-pico.

maxgerhardt avatar maxgerhardt commented on June 12, 2024

You're right, issue in pico-sdk opened per above.

from arduino-pico.

earlephilhower avatar earlephilhower commented on June 12, 2024

Closing here, being followed up on (hopefully) in the SDK repo...

from arduino-pico.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.