5 Replies Latest reply on Oct 21, 2020 1:02 AM by NiLe_4796031

    blocking spi full duplex

    NiLe_4796031

      If I understand correctly, there are two interfaces to Cy_SCB_SPI, the high-level interface which permits concurrent reads and writes but is asynchronous / interrupt driven, and the low-level interface which permits only reads or writes but allows you to choose asynchronous or blocking.

       

      I'm wrapping the Cypress SPI interface for calling code that expects a blocking SPI read+write function that starts communication immediately (the talk of FIFOs in the documentation makes me worry that sometimes the transfer is simply queued for later), and power usage I'd like to put the core to sleep until the interrupt indicating the transfer is complete (or other SPI state change) and for performance I'd like to avoid timeouts (either sleeping longer than needed or waking up too soon).

       

      I thought it was possible to build a blocking interface on top of Cy_SCB_SPI_Transfer where my interrupt handler sets a flag indicating that the transfer is done, but I'm encountering a race condition where the interrupt handler runs between the point where I check the flag and where I sleep for the next interrupt, leading to my core sleeping forever as no further interrupt arrives.

       

      I've also looked into building it on the low-level interface with Cy_SCB_SPI_Read and Cy_SCB_SPI_Write but these appear to just block until data is in the FIFO not until the communication is actually complete over the wire. See Re: Cy_SCB_SPI_ReadArray documentation  and Re: Use Low Level SPI read .

       

      Is there any way to do build a blocking full-duplex SPI function? Have I overlooked something in the API?

       

      My device is SPI master.