SPIS_GetRxBufferSize()

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

cross mob
DaCh_4286001
Level 3
Level 3
First like received First like given

I am trying to read RxBufferSize

   

  SPIM_PutArray(Tx_data,tx_byte_count);           //put first 10 elements  from data[] into Tx Buffer

    while((SPIM_ReadTxStatus() & SPIM_STS_TX_FIFO_EMPTY) != SPIM_STS_TX_FIFO_EMPTY );    //check if the transmit from master is completed

    Rx_buffersize = SPIS_GetRxBufferSize();         //#element in Rx buffer

However the Rx_buffersize is 0 after I compile it\

Regards,

Simon

0 Likes
1 Solution

Thank you Motto,

In my other article related to this. Bob suggests that I should never use delay or wait in ISR function. I tried that and now it is working.

Simon

View solution in original post

0 Likes
10 Replies
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

Hi Simon,

If the Rx_buffersize is 0 when you read SPIS_GetRxBufferSize(), I think it is possible that you have cleared your Rx buffer in your code.

Could you show us the function: SPIM_ReadTxStatus() ?

Suggestions:

You can design the logic of the program like this:

    /* Start transfer */
    SPIM_SpiUartPutArray(dummyBuffer, PACKET_SIZE);

    /* Wait for the end of the transfer. The number of transmitted data
    * elements has to be equal to the number of received data elements. */
    while (PACKET_SIZE != SPIM_SpiUartGetRxBufferSize());

    /* Clear dummy bytes from TX buffer */
    SPIM_SpiUartClearTxBuffer();

0 Likes

Hi LinglingG,

I don't think I clear the Rx buffer in my code. I just initialize all variables above the code I show in question.

I also tried the suggestion you give me but it looks like the biffer size counts from 4, then 8, then 9 and stops counting.

0 Likes
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

Please let me confirm if you connect interface signals of two components SPIM and SPIS.

Please refer "SPI_Design" code example for the UDB-based SPI module.

GS004116.png

Regards,

Noriaki

0 Likes

Yes I did.

Here is my sketch

pastedImage_0.png

0 Likes
lock attach
Attachments are accessible only for community members.

I can reproduce the phenomenon on my PSoC 5LP board by modifying the SPI_Design project example.

It seems that the following context does not work as you expected.

while ((SPIM_ReadTxStatus() & SPIM_STS_TX_FIFO_EMPTY) != SPIM_STS_TX_FIFO_EMPTY );

In the SPI Master component datasheet, it was described as follows.

Tx FIFO Empty: Set when the Tx Data FIFO is empty (does not indicate the Tx buffer RAM array conditions).

This means that this bit does not indicate the status of the software FIFO on the RAM area.  It just indicates the status of the hardware FIFO contained in UDBs.  So, no data bytes are sent to slave and the GetRxBufferSize() returns ZERO.

If you want to detect "the transmit from master is completed" as you write in the comment, SPIM_STS_SPI_DONE bit should be used.

while ((SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE) != SPIM_STS_SPI_DONE);

The GetRxBufferSize() returns 7 not 10.  This is because the size of software buffer is set to 8 in the project example.

If the software buffer sizes are increased to 16 for all combinations of SPIM/SPIS and RX/TX, the GetRxBufferSize() returns 10 meaning 10 elements are stored in the software FIFO.

Please refer attached project.

Regards,

Noriaki

Thank NoriakiT

Why no data bytes are sent to slave and the GetRxBufferSize() returns ZERO? in my mind After SPIM Tx FIFO, data will go into SPIS Rx FIFO. So if SPIM Tx FIFO is empty then the data are all transferred

Simon

0 Likes

Simon,

Maybe you see following description in the component datasheet.

GS004128.png

It just says "Tx FIFO empty" and also says "for more information, see Status Register Bits."

In the "Status Register Bits" section I found a strange description regarding the Tx FIFO Empty.

I suppose that "no data bytes are sent to slave" because the SPI clock frequency is very low and the CPU is going to write data bytes too quickly.

Regards,

Noriaki

Thank you Noriaki,

In my other article related to this. Bob suggests that I should never use delay or wait in ISR function. I tried that and now it is working.

Simon

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Since this topic seemed to be very interesting,

I downloaded Noriaki-san's sample and tried with my CY8CKIT-059.

As I don't have LCD I added following lines to see the result.

005-added.JPG

Meantime, I suspected that as you were not using Rx_buffersize anywhere in the source code.

I used it to call my dump_data() function, so that it will not be optimized out by the compiler.

When I hit the assignment line of Rx_buffersize, naturally Rx_buffersize was 0,

as it was not assigned.

001-Rx_buffersize_before.JPG

But when I stepped over the line, at the next statement,

Rx_buffersize was still ZERO.

002-Rx_buffer_size_middle.JPG

Then finally when I hit the line where I called my dump_data() with Rx_buffersize as an argument.

The Rx_buffersize has value of 0x0000000A!

003-Rx_buffersize_after.JPG

And in my TeraTerm the log was shown

004-TeraTerm-Log.JPG

So I believe that Rx_buffersize was actually assigned,

but somehow until it will be used, the debugger reported the value as ZERO.

moto

0 Likes

Thank you Motto,

In my other article related to this. Bob suggests that I should never use delay or wait in ISR function. I tried that and now it is working.

Simon

0 Likes