This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2540 read data from SPI slave

Other Parts Discussed in Thread: CC2540, CC2541

Hi :)

I have the CC2540 which is SPI master. But how do I read data from a SPI slave?

It seems like when I have to receive a byte I have to write a dummy-byte to MOSI. This powers SCLK and allows the SPI slave to write a byte to MISO in parallel.

Is this the only way to power SCLK and receive data from SPI slave?

And what if I intend to use DMA? Should I then on some trigger condition begin to write X dummy bytes using one DMA channel and then receive X bytes using another DMA channel? Or can DMA somehow power SCLK for reading X number of bytes?

(Yes, I am new to SPI ;)

Thanks :)

  • Hi Jens,

    Have a look at the HostTestRelease project for CC2541 (..\BLE-CC254x-1.3\Projects\ble\HostTestApp\CC2541). The CC2541SPI build uses the SPI driver in Slave mode (with or without DMA) and I believe you will find some useful code in the _hal_uart_spi.c file. Essentially, you are correct on your assumption regarding clocking out dummy data to read data.

    Note that this is for BLEv1.3

    Best Regards

  • Hi,

    Check out this design note, too: http://www.ti.com/lit/swra223. 

    Indeed, there is no way to 'read' SPI data from slave other than performing write, as it is only way to trigger SCLK appropriate number of times. Not a problem, though, as long as both master and slave stick to their higher level protocol.

    As of DMA, just set DMA channel to trigger on RX interrupt, arm the channel and then write dummies to slave intended number of times. 

     

    BR,

    Oleg