- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
PSoC 5 Device Programming
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Thank you very much !
Best regards,
Zvika