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

SPI driver implementation

Hi,

I'm using an nRF52840 and I need to implement a driver in c for an external chip. The c driver is written, and I only need to add specific functions regarding the SPI like a function for transmitting bytes and another function to receiving bytes. I tried using nrfx_spim_xfer with a transfer descriptor of NRFX_SPIM_XFER_TRX(NULL, 0, <receive buffer>, <receive buffer size>) for receiving bytes and  NRFX_SPIM_XFER_TRX(trBuffer, trCount/8, NULL, 0) for transmitting byte, but it does not seem to work. The driver is suppose handle the protocol, and the functions are more low-level, unlike the usual use of nrfx_spim_xfer.

Is there a different function I should use? Any suggestions for what should I do?

Thanks

Parents
  • Hi,

    Could you be more specific of what exactly doesn't work? Do you see any activities on the SPI lines? If you're going to use the the SPIM peripheral (SPI with Easy_DMA) then you would use NRFX_SPIM_XFER_TRX to set the buffers and nrfx_spim_xfer_dcx() to actually start the transfer. Have you seen the example in the SDK?

     
    regards
    Jared 
  • Hey,

    First of all, I meant "nrfx_spim_xfer"  function, not "NRFX_SPIM_XFER_TRX", Sorry for the confusion.

    Now, I'm seeing activities on the SPI signals. I used the nrfx_spim_xfer function to read SPI slave device ID, and it worked fine as follows (some signals polarity is reversed, but it does work):

    (Green is SCLK, Blue is MOSI, Pink is MISO and yellow is the chip select)

    The problem is when I need the Transmit and the Receive data as two separate functions, because that is the way this specific device driver works:

    I think the problem might be that the chip select signal is going high at the end of each nrfx_spim_xfer function call, so the device does not see it as a single action. Are there functions avaliable instead of nrfx_spim_xfer that can control those signals at a lower level? a function to lower chip select, a function to receive bytes, a function for transmit, etc? That will probably solve my issue.

    (Sorry for the long time to reply, Had a problem viewing the signals on scope).

    Thanks,

    Yuval

  • Hi,

     My understanding is that the issue is that the slave select signal is toggled between the transmit and receive operation when you call nrfx_spim_xfer () with the tx and rx buffer. You can control the slave select pin yourself by using the GPIO driver. Just set the ss pin to NRFX_SPIM_PIN_NOT_USED. You could then separate a tx and rx by calling the xfer twice. The psuedo code would look something like this:

    1. Set SS pin
    2. Call nrfx_spim_xfer(Set RX buffer to 0)
    3. Call nrfx_spim_xfer(Set TX buffer to 0)
    4. Clear SS pin. 

    Also, I think the image of the trace that you shared is a bit strange. Why is the there activity on the MOSI line and MISO line before the clock signal is active. Is there something else driving this line? 

  • Seems To work, Thank you very much!

    I'm not sure where the other activity is coming from

Reply Children
No Data
Related