PSOC 5L SPI Master Help

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

cross mob
PaFi_4802396
Level 1
Level 1
First reply posted First question asked First like given

I am trying to create a master SPI using PSOC 5. For debugging purposes I've set the clock to be 5 Hz (so I can track the sent and received data in real  time). The code I am using is below: 

int main(void){
CyGlobalIntEnable;
SPIM_1_Start();
LCD_Char_1_Start();
LCD_Char_1_PrintString("Waiting");

uint8_t recieved_byte = 0;

for (;;){if (Starting_Pin_Read() > 0){break;} else {CyDelay(100);}}

LCD_Char_1_ClearDisplay();
LCD_Char_1_PrintString("Starting");

SPIM_1_WriteTxData(0x00); // count is 0
SPIM_1_WriteTxData(0x00); // Status is "Ready"
SPIM_1_WriteTxData(0x0F); // LP is F
SPIM_1_WriteTxData(0x2D); // CRC from F is 2D
LCD_Char_1_PrintInt16(SPIM_1_GetTxBufferSize());
while (SPIM_1_GetTxBufferSize()>0){CyDelay(1000);} // Waiting for all words to be sent


CyDelay(4000);
LCD_Char_1_ClearDisplay();
LCD_Char_1_PrintString("Recieved Data:");
LCD_Char_1_Position(1, 0);
for (int i = 0; i<4; i++){
while (SPIM_1_GetRxBufferSize() < 1) {
CyDelay(1000);
} // Waiting till we get a next word

if (SPIM_1_GetRxBufferSize()>0) {
recieved_byte = SPIM_1_ReadRxData();
LCD_Char_1_PrintHexUint8(recieved_byte); //displaying recieved word
}
}

 

So I would expect the TxBufferSize to not be 0 when I am printing it out, but it is. What am I doing wrong? 

My configuration of SPI_Master is

PaFi_4802396_0-1619787135889.png

If one needs additional documents to replicate, I will happily send my source code!

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

PaFi,

Do you have the Tx software buffer enabled?

I found this function description in the datasheet for the SPI_Master.

uint8 SPIM_GetTxBufferSize(void)
Description:
Returns the number of bytes/words of data ready to transmit currently held in the Tx buffer.
▪ If Tx software buffer is disabled, this function returns 0 = FIFO empty, 1 = FIFO not full, or 4 = FIFO full.
▪ If the Tx software buffer is enabled, this function returns the size of data in the Tx software buffer. FIFO data not included in this count.

Return Value:  uint8: Integer count of the number of bytes/words in the Tx buffer

Side Effects:  Clears the Tx status register of the component.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
1 Reply