Why status register take the program into forever chk mode?

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

cross mob
Anonymous
Not applicable

Hello Every body,

   

I am doing SPI communication between Pi and PSOC 5LP.

   

I placed a command

   

while(!(SPIS_ReadTxStatus() & SPIS_STS_SPI_DONE));

   

But by doing this, my program just takes too long to fulfill the condition and when I replace the above condition with just:

   

while(!(SPIS_STS_SPI_DONE));

   

It does not!

   

I wonder why it is behaving so wierd?

   

Looking forward to your answers!

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

while(!(SPIS_STS_SPI_DONE));

   

The above is testing a constant value for zero. SPIS_STS_SPI_DONE is a #defined value to check for a bit pattern. Checking with
while(!(SPIS_ReadTxStatus() & SPIS_STS_SPI_DONE));
will indeed consume MIPS. Think about to use a "callback macro". Look for that term in SPI datasheet and in Creator help.

   

 

   

Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

while(!(SPIS_STS_SPI_DONE));

   

The above is testing a constant value for zero. SPIS_STS_SPI_DONE is a #defined value to check for a bit pattern. Checking with
while(!(SPIS_ReadTxStatus() & SPIS_STS_SPI_DONE));
will indeed consume MIPS. Think about to use a "callback macro". Look for that term in SPI datasheet and in Creator help.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

while(!(SPIS_ReadTxStatus() & SPIS_STS_SPI_DONE));
will wait until the SPI communication really is finished. Yes, this will take time since it takes a while for that (depending on your SPI clock speed). There is nothing you can do about it.

   

Using a callback macro can help you to use the CPU during that time for something else (e.g. it can sleep, or calculate something else). But in any case, the time needs to be spend.

Anonymous
Not applicable

Thank you Bob and hli for your suggestions. 

   

I have a problem with buffer synchronization between pi and psoc. Any suggestion how i can over come this?

0 Likes