joan2937 / pigpio

pigpio is a C library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).
The Unlicense
1.43k stars 403 forks source link

SPI Slave - BSCX not consistently working RPi4B #601

Closed karlo922 closed 2 months ago

karlo922 commented 4 months ago

I have a ESP32 set to an SPI Master with 100kHz, Mode 2 and just want to send 0x19 to the RPi4 running pigpiod and using shell for output. When I use piscope, everything seems fine for me on the pins: grafik

But pigs bscx 0x213 or also pigs bscx 0x21B always just returns 1 18 so an empty buffer.

From RPi Perspective the connections are as following: CE0: GPIO 8 - Pin24 ->> ESP32 - GPIO 5 (CS) MISO: GPIO 9 - Pin23 ->> ESP32 - GPIO 23 (MOSI) MOSI: GPIO 10 - Pin 19 -- not connected SCLK: GPIO 11 - Pin 23 ->> ESP32 - GPIO 18 (SCLK)

What could be wrong? I had it once working yesterday, but kind of unstable. I do not know what I could have changed, but now nothing works.

guymcswain commented 4 months ago

BSC MISO is pin 10 on RPI4b according to docs.

karlo922 commented 4 months ago

You mean GPIO10 or Pin10? Where do you find that? I now tried GPIO10 but this does not change anything apart that piscope now shows that 10-MOSI gets the signal.

guymcswain commented 4 months ago

GPIO10 or pin number 19. Here

karlo922 commented 4 months ago

After trying out the given BitBang example which worked, I tried to change my ESP32 so that it always sends twice - now it works.. Thank you, although I still do not really understand the issue. (with ESP32 sending to GPIO10 like you said) I always 2 byte needed?

grafik

guymcswain commented 4 months ago

It's been a while since I've played with the BSC-SPI peripheral. From the documentation, it appears the LSB of the first byte on MOSI controls whether data is to be written to the BSC-SPI FIFO or read from the BSC-SPI FIFO. So yes, you need to send two bytes to send one data byte.

The BSC slave in SPI mode deserializes data from the MOSI pin into its receiver/ FIFO when the LSB of the first byte is a 0. No data is output on the MISO pin. When the LSB of the first byte on MOSI is a 1, the transmitter/FIFO data is serialized onto the MISO pin while all other data on the MOSI pin is ignored.

karlo922 commented 2 months ago

I guess all info is here - we can close it.