raspberrypi / pico-micropython-examples

Examples to accompany the "Raspberry Pi Pico Python SDK" book.
BSD 3-Clause "New" or "Revised" License
1.01k stars 228 forks source link

PICO2 with python case SPI SLAVE MODE #80

Closed bawanqin1987 closed 1 month ago

bawanqin1987 commented 1 month ago

hi sir i wanna code the py case with spi slave mode on PICO2,and the other soc board spi with master mode and send data but pico2 receive data error,all data is 0xff, spi slave py case

and,i catch the signal with my soc board,the signal data as below: soc board send mosi

please make sure the py case support spi slave mode? pico2 spi slave soc board send mosi

bawanqin1987 commented 1 month ago

from machine import Pin, SPI import time

初始化SPI对象

spi = SPI(0)

配置SPI参数

spi = SPI(0, 1000000, polarity=1, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(2), mosi=Pin(3), miso=Pin(4))

配置片选引脚

cs = Pin(5, Pin.IN)

短暂延迟,等待接收数据

time.sleep(2)

设置引脚输出高电平

接收数据

received_data = bytearray(512)

time.sleep(5)

拉低片选引脚,选择从设备

cs.value(0)

发送空字节以触发从设备的数据传输

spi.write(b'\x00') received_data = spi.read(512) cs.value(1) time.sleep(1)

打印接收到的数据

print("Received data:", received_data)

lurch commented 1 month ago

This isn't related to the examples in this repo. You should ask for more help at https://github.com/orgs/micropython/discussions an/or https://forums.raspberrypi.com/viewforum.php?f=146

lurch commented 1 month ago

P.S. I found a comment https://github.com/orgs/micropython/discussions/10442 from January 2023 saying that Micropython doesn't yet support SPI slave mode.