cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

New Contributor II

Hello,

I have to receive 8 bytes message via SPI.

What is the right way doing it in polling, without any interrupts.

For writing, I used SPIS_PutArray . But there is no SPIS_GetArray.

Thank you,

Zvika

0 Likes
Reply
1 Solution
Contributor II

There's no GetArray, but you have ReadRxStatus, GetRxBufferSize, and ReadRxData, so you've got what you need to read out bytes.

You would do something to this effect:

#define MAX_NUM_BYTES    64    /*Can be whatever arbitrary limit is decided*/

uint8_t SPIS_InBytes[MAX_NUM_BYTES] = {0};

void Process_SPIS_In(void){

    uint8_t num_bytes = SPIS_GetBufferSize();

    uint8_t byte_index = 0;

/*Read SPI bytes in until there are none left in the FIFO*/

    while ((SPIS_ReadRxStatus() & SPIS_STS_RX_FIFO_NOT_EMPTY) != 0){

        SPIS_InBytes[byte_index++] = SPIS_ReadRxData();

        /*For safety, make sure we are not exceeding MAX_NUM_BYTES*/

        /*Loop back to the first index - we could also decrement byte_index to only overwrite the last index */

        if (byte_index >= MAX_NUM_BYTES){

            byte_index = 0;

        }

    }

}

You would also need to reset byte_index to 0, as well as clear out SPIS_InBytes[] for the next transmission when you determine your message is "done", however you choose to decide that (number of bytes received?  End of Packet byte?) is up to you.

View solution in original post

2 Replies
Contributor II

There's no GetArray, but you have ReadRxStatus, GetRxBufferSize, and ReadRxData, so you've got what you need to read out bytes.

You would do something to this effect:

#define MAX_NUM_BYTES    64    /*Can be whatever arbitrary limit is decided*/

uint8_t SPIS_InBytes[MAX_NUM_BYTES] = {0};

void Process_SPIS_In(void){

    uint8_t num_bytes = SPIS_GetBufferSize();

    uint8_t byte_index = 0;

/*Read SPI bytes in until there are none left in the FIFO*/

    while ((SPIS_ReadRxStatus() & SPIS_STS_RX_FIFO_NOT_EMPTY) != 0){

        SPIS_InBytes[byte_index++] = SPIS_ReadRxData();

        /*For safety, make sure we are not exceeding MAX_NUM_BYTES*/

        /*Loop back to the first index - we could also decrement byte_index to only overwrite the last index */

        if (byte_index >= MAX_NUM_BYTES){

            byte_index = 0;

        }

    }

}

You would also need to reset byte_index to 0, as well as clear out SPIS_InBytes[] for the next transmission when you determine your message is "done", however you choose to decide that (number of bytes received?  End of Packet byte?) is up to you.

View solution in original post

New Contributor II

Hello,

Thank you very much !

Best regards,

Zvika

0 Likes
Reply