- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
If one needs additional documents to replicate, I will happily send my source code!
Solved! Go to Solution.
- Labels:
-
PSOC5 LP MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
"Engineering is an Art. The Art of Compromise."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
"Engineering is an Art. The Art of Compromise."