SPI on the RP2040 (Pico)

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
TomGloard
Posts: 2
Joined: Wed Jul 27, 2022 1:17 am

SPI on the RP2040 (Pico)

Post by TomGloard » Wed Jul 27, 2022 1:32 am

Hi, im trying to get the SPI up and running on my Pico board. Im writing to a scratchpad reg (0x07)
Watching the signals on my Logic analyzer everything seems fine
Image

The code is basically the following:

Code: Select all

cs = machine.Pin(21, machine.Pin.OUT)
spi = machine.SPI(0, baudrate=10000, polarity=0, phase=0, bits=8,
                  firstbit=machine.SPI.MSB, sck=machine.Pin(18), mosi=machine.Pin(19), miso=machine.Pin(20))

def ping(spi, cs): 
    reg_write(spi, cs, REG_SPR, 0x55)
    data = reg_read(spi, cs, REG_SPR)
    print(data)
    if data == 0x55: 
        print('pong')
    else: 
        print('Error')

ping(spi,cs) 
Where i'm doing some bitshifting in the reg_write and reg_read to have the address on the correct location.
So from the image we see the initial write of 0x55 and afterwards we're reading the same reg and from the logic analyzer the device answers correctly with 0x55. However the output of micropython is:

Code: Select all

b'\x00'
Error
Has anyone encountered this issue?

TomGloard
Posts: 2
Joined: Wed Jul 27, 2022 1:17 am

Re: SPI on the RP2040 (Pico)

Post by TomGloard » Wed Jul 27, 2022 8:16 am

Just tried with the softSPI implementation and this works as expected and I receive:
b'U' which is the ascii character for 0x55. Is this a known bug? And any idea how to make the hardware SPI behave?

Thanks - Tom

Post Reply