Hello,
I am using an nRF52840PDK (master) to use an SPI peripheral, where my code is based on examples\peripheral\spi. My IDE is Segger Embedded Studio and I am using SDK 15.0.0. I am using an oscilloscope to visualize the SPI bus activity.
I start of by configuring the SPI peripheral hardware on the nRF52840. Afterwards I write my configurations into the external peripheral registers over SPI. All of this works as expected.
Following is my problem:
I am trying to read from one of the registers. To do this I write my command byte and want to read 2 bytes (1 status & 1 data). I can see both MOSI and MISO lines reflect the correct data with the oscilloscope. The data does however not seem to be getting loaded into the receive buffer.
Using the debugger I can see being stuck in an endless loop (peripheral.c, register_read(), thus the spi_event_handler is not called to set spi_transfer_done = true. My first suspicion was my event_handler pointer. This works during writing so should also work during reading. Using a watch on the rx_buffer shows me that it is not being filled.
Below this is are scope images and my relevant code. At the very bottom is the concrete question.
Both of the devices are in SPI mode 0.
Yellow = MOSI - blue = MISO - grey line = SCLK 2 periods (external trigger edited in manually) ---- The first MISO byte is a status byte and discarded, second byte is data
Image writing register 17:
MOSI [command, data] - MISO [status]
Image reading register 17:
MOSI[command] - MISO[status, data]
main.c:
peripheral.h:
peripheral.c:
Regarding the SPI mode: the nRF52840 is in mode0 (SCK active high, sample on leading edge of clock) while the documentation of my peripheral reads:
"[...] These signals are represented in the form (CPOL, CPHA). An
interface that expects both positive edge SCKS and the MOSI data to be available before the first
positive clock edge, can operate in modes (0,0) and (1,1) without alteration. […]"
My question is: Why am I getting stuck in this endless loop and how can I fix it?
Thank you in advance (this is quite long),
Kevin
Edit: Corrected image discription
P.s.: I think there is a bug where I can't upload, remove, then reupload a different image with the same name. It will then show the first image again in the editor.