- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm trying to find more ways to transfer multiple bytes (arrays) via SPI, for now i'm sending one by one (see the for loop):
void WriteLongRegister(const uint8_t *data, const size_t dataSize)
{
if ( NULL == data ) { return; }
uint8_t i;
SPI_ClearRxBuffer();
SPI_ClearTxBuffer();
SS_Write(0);
for(i = dataSize; i != 0; i--)
{
SPI_WriteTxData(data[dataSize - i]);
}
while(0 == (SPI_ReadTxStatus() & SPI_STS_SPI_IDLE));
SS_Write(1);
}
So, now i'm thinking about filling the SPI FIFO buffer and waiting for it to get empty to fill it again until transfer the whole array. Here's a ruff idea, haven't tested in real PSoC
static void sendArray(const uint8_t* array, size_t size)
{
if( array == NULL ) return;
uint8_t i;
SS_Write(0); // SS pin low
// "array" will be placed on the SPI Tx buffer
// in blocks, not one by one, so we need to
// calculate the rest bytes
// let's say array is 22 bytes long,
// and SPI_TX_BUFFER_SIZE is 4 bytes
// We need to send array in 6 blocks
// 5 blocks of 4 bytes and other block of 2 bytes
// rest = 2 bytes
uint8_t rest = size % SPI_TX_BUFFER_SIZE;
// here we send the 5 blocks
for( i = 0; i <= size; i += SPI_TX_BUFFER_SIZE )
{
SPI_PutArray( &array, SPI_TX_BUFFER_SIZE );
}
// Here send the rest of the array
// i don't know how yet 😞
SPI_PutArray( &array[size - rest], rest );
SS_Write(1); // SS pin idle
}
What do you think?
any improvements?
is worth the optimization (controlling or sending data to TFT displays can be improve with this)?
More ways to send "large" arrays via SPI without sending byte by byte?
Thanks in advance
Carlos
PD: Will attach the project later today.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can actually put a larger array into SPI_PutArray, and it will take care of putting it correctly into the TX FIFO.
If you care about CPU utilization, use a DMA.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You are totally right!, silly me, i didn't read the Side Effects section of the x_PutArray function.
(i tried a lot of times getting the SPI work with DMA but never succeed, but that's another story hehe).
Thanks for pointing out the right usage of x_PutArray function :).
Carlos