Just going by what is in your zip file-
as my previous post says, you will never get out of that do loop as you are following the example code in the spi header.
The header example is bad, lets review-
uint16_t myWriteBuffer[MY_BUFFER_SIZE];
uint16_t myReadBuffer[MY_BUFFER_SIZE];
uint16_t writeData;
uint16_t readData;
SPI1_STATUS status;
unsigned int total;
SPI1_Initialize;
total = 0;
do
{
total = SPI1_Exchange16bitBuffer( &myWriteBuffer[total], MY_BUFFER_SIZE - total, &myWriteBuffer[total]);
// Do something else...
} while( total < MY_BUFFER_SIZE );
leaving aside the question of why they are not using myReadBuffer here, lets start with what SPI1_Exchange16bitBuffer is supposed to return according to the header-
@Summary
Returns the value of the status register of SPI instance : 1
but if you look at the source of SPI1_Exchange16bitBuffer, it calls SPI1_ExchangeBuffer, so if we look at that we find that it returns dataSentCount (not spi status).
if you work your way through 'SPI1_ExchangeBuffer' you will find 'while (dataSentCount < byteCount)', so effectively what returns is 'byteCount'.
what is byteCount? it is the BYTE count of what we want sent through spi, and you will see it gets converted to a WORD count (I'm calling 16bit a WORD here) IF in 16bit mode-
if (spiModeStatus == SPI1_DRIVER_TRANSFER_MODE_16BIT)
{
addressIncrement = 2;
byteCount >>= 1;
}
OK, back to the do loop-
total = 0
MY_BUFFER_SIZE = 2
first time through-
total = SPI1_Exchange16bitBuffer( &myWriteBuffer[0], 2 - 0, &myWriteBuffer[0]);
the byteCount was converted to 1 (2>>1 = 1)
total is now set to 1 (return value is always same as converted byteCount)
second time through-
total = SPI1_Exchange16bitBuffer( &myWriteBuffer[1], 2 - 1, &myWriteBuffer[1]);
the byteCount was converted to 0 (1>>1 = 0)
total is now set to 0 (return value is always same as converted byteCount)
as you can see, total will never increment to get out of the do loop, and in the bad example here you will actually get 1 word repeatedly sent (total keeps changing from 1 to 0)
if you 'fix' one problem they have and use 'total +=', in this case the result will be that total will get stuck at 1 so only 1 word would be sent
however, if you do as I posted previously
total += SPI1_Exchange16bitBuffer(&myWriteBuffer[total], 2, &myReadBuffer[total]);
(switching to SPI1, since you are using SPI1 now)
total will increment by 1 every time through, and you will no longer be stuck in that do loop
(I would add, the code I linked to is not tested and could be wrong, it was just to show the type of code MCC should generate)