3 Replies Latest reply on Jun 18, 2019 11:04 PM by VisonZ_71

    SPI (SPIM_PutArray())

    DaCh_4286001

      I am currently just trying to write a simple SPI to transmit string from master to slave.

      I would like to use SPIM_PutArray() to transmit data.

      I know this PutArray function will put contents in the string into transmit buffer. I guess after PutArray, I can use SPIM_GetTxBufferSize() to read the tx buffer size. However, in debug mode, this buffer size is shown as 1 which should supposed to be 10. Are there any thing I miss here?

       

       

      uint8 Tx_data[20] = {'a','b','c','d','e','f','g','h','i','j'};

       

      SPIM_PutArray(Tx_data,10);         //send data[] from master to slave

      Tx_buffersize = SPIM_GetTxBufferSize();

       

      Regards,

      Simon

        • 1. Re: SPI (SPIM_PutArray())
          JoMe_264151

          Are there any thing I miss here?

          Yes, you are too fast. The PutArray() API is non-blocking when the transmit buffer is large enough. So your reading GetTxBufferSize() just shows that the complete transfer to the slave is not done yet.

           

          Bob

          • 2. Re: SPI (SPIM_PutArray())
            DaCh_4286001

            So for the putArray(), it will put data on tx buffer and send data automatically to slave? I thought it will keep the data in buffer

            • 3. Re: SPI (SPIM_PutArray())
              VisonZ_71

              void SPIM_1_PutArray(const uint8 buffer[], uint8 byteCount)                                                                    

              {

                  uint8 bufIndex;

                  bufIndex = 0u;

                  while(byteCount > 0u)

                  {

                      /* Wait until TX FIFO has a place */

                      while(0u == (SPIM_1_TX_STATUS_REG & SPIM_1_STS_TX_FIFO_NOT_FULL))

                      {

                      }

                      /* Put data element into the TX FIFO */

                      CY_SET_REG8(SPIM_1_TXDATA_PTR, txData);

               

                      bufIndex++;

                      byteCount--;

                  }

              }