Page 1 of 1

[SOLVED] SPI on the Pico: has anyone made it work?

Posted: Sat Feb 13, 2021 4:38 pm
by pythoncoder
I'm struggling to get SPI working, either hard or soft.

Issuing a soft SPI write produces a clock burst of the specified frequency but the data pin is stuck low. I've tried different data pins to no effect. I am using the machine.SoftSPI constructor.

If anyone has got hard or soft SPI output to work, please could you post your SPI initialisation code.

Re: SPI on the Pico: has anyone made it work?

Posted: Sat Feb 13, 2021 5:53 pm
by fdufnews
I have adapted a driver for an oled display using sh1122. It is using SPI. Code is here viewtopic.php?f=14&t=9769 it runs without any problem on my Pico.

Re: SPI on the Pico: has anyone made it work?

Posted: Sat Feb 13, 2021 8:36 pm
by Roberthh
Hello Peter, I have used your flash_spi driver to attach a SPI flash chip as drive. Start-up code:

Code: Select all

from machine import SPI, Pin
import os
spi = SPI(0, baudrate=10_000_000, polarity=1, phase=1,
            sck=Pin(18), mosi=Pin(19), miso=Pin(16))

from flash_spi import FLASH
cspins = (Pin(17, Pin.OUT, value=1),)
flash = FLASH(spi, cspins, cmdset=False)
os.mount(flash, "/spi")
print(os.listdir("/spi"))

Re: SPI on the Pico: has anyone made it work?

Posted: Sun Feb 14, 2021 1:49 pm
by pythoncoder
Thanks both, I'll try again; maybe I was suffering from "finger trouble".

@Roberthh interesting that you are using hard SPI on nonstandard pins. I didn't know you could do that on the rp2, although the Pi Pico doc hints at it by referring to "default SPI pins".

Re: SPI on the Pico: has anyone made it work?

Posted: Sun Feb 14, 2021 2:49 pm
by Roberthh
I just did that w/o reading the docs. I just had looked at the Pinout. But i had glanced before into the code and noticed that is checked for a variety of pins for being valid.

Re: SPI on the Pico: has anyone made it work?

Posted: Sun Feb 14, 2021 3:27 pm
by pythoncoder
Well I don't know what I was doing yesterday but today it's working fine. Thanks for the pointers.

Re: [SOLVED] SPI on the Pico: has anyone made it work?

Posted: Mon Apr 26, 2021 12:06 pm
by ilium007
So does uC on the rp2040 support SPI and I2C? I was holding off because I thought they weren’t able to do either yet.

Re: [SOLVED] SPI on the Pico: has anyone made it work?

Posted: Mon Apr 26, 2021 12:30 pm
by Roberthh
Both SPI and I2C work with Micropython on RP2.