Greetings!
I'm trying to set up an nRF52 board as an SPI slave so that it would receive chunks of data irregularly from the master device (a Raspberry Pi in this case, if it's important). However, I am not sure if I understand correctly the purpose of the SPIS API and how exactly should I use it. Here is how I'm doing it currently:
(I understand that I suppose to adjust buffers after transfers, but I don't think it's important for now).
Issue is, I'm not sure I completely understand the
nrfx_spis_buffers_set
function.I.e, here is how I understand what I am doing. Please correct me if I misunderstood anything:
1. Init SPI device
2. Tell SPI that I have a RX and TX buffers ready with
nrfx_spis_buffers_set
3. When Master initiates transfer, Master and Slave exchange bytes, up to
tx_buffer_length
bytes sent and rx_buffer_length
received4. After the transfer, event handler is called with
NRFX_SPIS_XFER_DONE
event type, tx_amount bytes transferred and rx_amount bytes received5. Within the event handler, I must updates buffers if necessary and call
nrfx_spis_buffers_set
again with new data to be read/sentFor reference, here is the code for raspberry pi:
So I'm trying to exchange "hello, world" string from raspberry pi and "HELLO" string from nRF52. However, in the end, I get something messed up:
And on raspberry pi side:
(I understand that I keep sending HELLO over and over again, but where did that D even came from?)
I was able to get a proper result once (i.e. withtin a single transfer, 12 bytes in one direction, 6 in another, all properly sent), but I was never able to get that again.
I think I should also mention that I tried enabling anomaly 109 workaround, but then I can't even init SPIS because of NRFX_ERROR_INTERNAL.
What am I doing wrong? I have a suspicion that I'm messing up buffers by declaring them like that; But is my understand of the process of SPI transfer correct? What here could cause those incomplete (and sometimes incorrect) transfers? What could be improved in the code?
Thanks in advance.