Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

Default SPI frequency?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Default SPI frequency?

by thezim on Tue Jan 11, 2022 10:46 am

Working with a Sparkfun Thing+ RP2040

Code: Select all | TOGGLE FULL SIZE
spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
print(f"SPI frequency: {spi.frequency}")

This prints:

SPI frequency: 0

So what is the default SPI frequency being used here? Is default SPI frequency define in the board module, if so where.

The following does display the frequency.

Code: Select all | TOGGLE FULL SIZE
spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
spi.try_lock()
spi.configure(baudrate=24000000)
spi.unlock()
print(f"SPI frequency: {spi.frequency}")

SPI frequency: 20833333

thezim
 
Posts: 7
Joined: Fri Jun 16, 2017 3:37 pm

Re: Default SPI frequency?

by danhalbert on Tue Jan 11, 2022 11:21 am

You have found a bug! The default SPI frequency is 250kHz, but the `busio.SPI()` constructor fails to set an internal variable that remembers the frequency that was set.

Tracking the bug here: https://github.com/adafruit/circuitpython/issues/5836

Thanks for noticing this!

danhalbert
 
Posts: 3182
Joined: Tue Aug 08, 2017 12:37 pm

Re: Default SPI frequency?

by thezim on Tue Jan 11, 2022 12:46 pm

danhalbert wrote:You have found a bug! The default SPI frequency is 250kHz, but the `busio.SPI()` constructor fails to set an internal variable that remembers the frequency that was set.

Tracking the bug here: https://github.com/adafruit/circuitpython/issues/5836

Thanks for noticing this!


For my edification exactly where is 250kHz defined in the code? I had trouble tracking down what repo has this code in it.

Thanks.

thezim
 
Posts: 7
Joined: Fri Jun 16, 2017 3:37 pm

Re: Default SPI frequency?

by danhalbert on Tue Jan 11, 2022 12:49 pm

For my edification exactly where is 250kHz defined in the code? I had trouble tracking down what repo has this code in it.
Here is where it is set:
https://github.com/adafruit/circuitpyth ... /SPI.c#L93

danhalbert
 
Posts: 3182
Joined: Tue Aug 08, 2017 12:37 pm

Re: Default SPI frequency?

by thezim on Tue Jan 11, 2022 1:48 pm

danhalbert wrote:
For my edification exactly where is 250kHz defined in the code? I had trouble tracking down what repo has this code in it.
Here is where it is set:
https://github.com/adafruit/circuitpyth ... /SPI.c#L93


Thanks. As an aside is code search busted on GitHub?

https://github.com/adafruit/circuitpyth ... ever_reset

Why does this not find any code an only issues?

thezim
 
Posts: 7
Joined: Fri Jun 16, 2017 3:37 pm

Re: Default SPI frequency?

by danhalbert on Tue Jan 11, 2022 2:12 pm

It does not find code because adafruit/circuitpython is a fork of micropython/micropython, and GitHub doesn't search forks. So we'd recommend cloning the repo and doing local searches for now.

GitHub's new codesearch, https://cs.github.com, does search forks, but it is in limited-invite beta. (I got a beta invitation this morning and just tried searching.)

danhalbert
 
Posts: 3182
Joined: Tue Aug 08, 2017 12:37 pm

Re: Default SPI frequency?

by rsbohn on Thu Jan 20, 2022 7:40 pm

I think this goes beyond just reporting the wrong frequency.

Trying to drive the 1.14" PiTFT on the Pi Zero W. It takes 136 seconds to fill the 135x240 screen with a constant color565 value. This doesn't seem to be running at 64 MHz.

If it reports a faster frequency the screen fill takes less than one second. If `spi.frequency==0` don't even bother loading the display driver. Request a hard reset and hope for a better result next time around.

rsbohn
 
Posts: 11
Joined: Tue Feb 22, 2011 5:55 pm

Re: Default SPI frequency?

by tannewt on Fri Jan 21, 2022 1:52 pm

@rsbohn, that's a separate issue with the broadcom port. I think you've filed an issue already, so that's the place to discuss it.

tannewt
 
Posts: 2907
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.