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

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Sat Feb 13, 2021 4:38 pm

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.
Peter Hinch
Index to my micropython libraries.

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

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

Post by fdufnews » Sat Feb 13, 2021 5:53 pm

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.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

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

Post by Roberthh » Sat Feb 13, 2021 8:36 pm

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"))

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Sun Feb 14, 2021 1:49 pm

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".
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

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

Post by Roberthh » Sun Feb 14, 2021 2:49 pm

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Sun Feb 14, 2021 3:27 pm

Well I don't know what I was doing yesterday but today it's working fine. Thanks for the pointers.
Peter Hinch
Index to my micropython libraries.

ilium007
Posts: 37
Joined: Tue Feb 16, 2021 10:29 am

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

Post by ilium007 » Mon Apr 26, 2021 12:06 pm

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.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

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

Post by Roberthh » Mon Apr 26, 2021 12:30 pm

Both SPI and I2C work with Micropython on RP2.

Post Reply