SPI (SPIM_PutArray())

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaCh_4286001
Level 3
Level 3
First like received First like given

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

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes

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

0 Likes

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--;

    }

}

0 Likes