Skip to content

SPI LIbrary Does Not Honor Clock Polarity Setting #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
YorkBW opened this issue Oct 9, 2015 · 12 comments
Closed

SPI LIbrary Does Not Honor Clock Polarity Setting #874

YorkBW opened this issue Oct 9, 2015 · 12 comments

Comments

@YorkBW
Copy link

YorkBW commented Oct 9, 2015

Essentially, SPI modes 0 and 1 are unsupported; if these modes are requested, you actually get modes 2 and 3 respectively. It's noted in the source that setting the hardware SPI clock polarity is "TBD," but I don't think that's documented anywhere outside the source.

@igrr
Copy link
Member

igrr commented Oct 9, 2015

This is mentioned in reference:

https://github.com/esp8266/Arduino/blob/esp8266/hardware/esp8266com/esp8266/doc/reference.md#spi

On Fri, Oct 9, 2015, 17:45 Brent W. York [email protected] wrote:

Essentially, SPI modes 0 and 1 are unsupported; if these modes are
requested, you actually get modes 2 and 3 respectively. It's noted in the
source that setting the hardware SPI clock polarity is "TBD," but I don't
think that's documented anywhere outside the source.


Reply to this email directly or view it on GitHub
#874.

@YorkBW
Copy link
Author

YorkBW commented Oct 9, 2015

Thanks! Although that document says modes 2 and 3 aren't supported, while I think it's the other way round. I had to set an external commercial module to accept mode 2 for it to work with the ESP8266.

@YorkBW
Copy link
Author

YorkBW commented Oct 9, 2015

After my too-brief research, I'm suspecting that playing around with values for SPI_CLKCNT_H and SPI_CLKCNT_L might be a way to flip the clock polarity; unfortunately I don't have the toolchain installed right now to test and contribute. And hey -- thanks for making this code available, it has saved me a ton of time!!!

@igrr
Copy link
Member

igrr commented Oct 12, 2015

If you got ESP8266 Arduino core installed, then you do have a toolchain installed. You can experiment with those settings by adding necessary .h/.cpp files to the sketch.

@Duality4Y
Copy link
Contributor

I have done research on implementing this, and I am not sure if the esp8266 hardware supports it. at-least it doesn't show in the research I did.

@igrr
Copy link
Member

igrr commented Mar 23, 2016

Fixed in #1781

@0xPIT
Copy link

0xPIT commented Mar 26, 2016

I've tested just now with my logic analyzer. Unfortunately, it does not work.
I've also tried all modes (0,1,2,3) and SCK always idles in low state, whereas with CPOL=1 (in modes 2 & 3) it should idle at high.

@Duality4Y where did you find the info about bit 29 in SPI1P is setting CPOL?

@0xPIT
Copy link

0xPIT commented Mar 26, 2016

Also, contrary to the initial report from @YorkBW, actually only modes 0 and 1 are supported, as the clock always idles at low. Modes 2 & 3 would require the clock idling in high state, which does not work.

See here: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Clock_polarity_and_phase

@0xPIT
Copy link

0xPIT commented Mar 26, 2016

OK, I'm wrong. The CPOL Setting works, but the problem might be something different: Obviously, when I initialize with SPI_MODE0, the mode can not be changed later.

@Duality4Y
Copy link
Contributor

@0xPIT I think you didn't meen to mention me?

@igrr
Copy link
Member

igrr commented Mar 28, 2016

@igrr
Copy link
Member

igrr commented Mar 28, 2016

BTW, as it is pointed out in the source linked above, CPHA needs to be inverted when CPOL == 1. I think this needs to be fixed in our code as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants