This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI Slave: inspect data before transfer complete?

I'm trying to emulate an nRF24L01+ SPI slave interface with an nRF51822. The nRF24L01+ interprets the first byte in the SPI transfer as a "command", and the data that it will shift out in the same SPI transaction depends on the first byte received from the master.

Looking at the SPIS peripheral in the nRF51 reference manual, it does not appear that I emulate this behaviour. If I set MAXRX to 1, the rest of the SPI transaction will be ignored, and it doesn't look like I can implement a polling method to see when the first byte comes in.

Is there a way that I can emulate an nRF24L01+ SPI implementation with the nRF51822?

edit: Just to be clear: I'm not trying to emulate the whole nRF24L01+; I want to fake out a device that talks to an nRF24L01+ over a 400kHz SPI link just enough to be able to say "I have a new packet, here is the data" and that's about it. The data for the packet would of course come from BLE instead of a proprietary 2.4GHz link.

Parents
  • I don't think there are any easy way to do this. If you are going to use the SPI slave hardware peripheral (SPIS), there are no other events generated from this peripheral than END and ACQUIRED. END tells you when the whole transmission has finished, and ACQUIRED is when the SPIS has been granted access to the RXDPTR and TXDPTR registers. So, there is no event that tells you when only the first byte has been received.

    You can try to write your own software SPI slave that does this, but I don't think the nRF51822 is fast enough to do the processing that needs to be done after the first byte has been received, in order to shift out valid data on the next byte. This was done in hardware on the nRF24L01, and hence a lot faster.

Reply
  • I don't think there are any easy way to do this. If you are going to use the SPI slave hardware peripheral (SPIS), there are no other events generated from this peripheral than END and ACQUIRED. END tells you when the whole transmission has finished, and ACQUIRED is when the SPIS has been granted access to the RXDPTR and TXDPTR registers. So, there is no event that tells you when only the first byte has been received.

    You can try to write your own software SPI slave that does this, but I don't think the nRF51822 is fast enough to do the processing that needs to be done after the first byte has been received, in order to shift out valid data on the next byte. This was done in hardware on the nRF24L01, and hence a lot faster.

Children
  • Yes, I spent a few hours last night with the pin change interrupt and spinning on the received byte to see when it was received. I can detect this and respond quickly enough but as soon as I try to do any data processing (i.e. responding differently to different command bytes) it falls down and my response is sent in the third byte instead of the second.

    at 16MHz there just isn't enough time. At 32MHz there may be, but I think that after the BLE soft device has taken its toll in CPU time I'll be back to where I started.

Related