10 Replies Latest reply on May 1, 2015 5:34 AM by DaKn_263916

    basic UART question

      New to PSoC as maybe seen in a previous post, however I'm working with UART. I'm wondering why my if statements aren't getting any coming in true? I'm almost positive it's something simple. I looked at the datasheet for the UART module.


      Essentially I'm looking for the status registers to be ready by polling(as asked for)



          uint16 readIterator=0;


          uint16 writeIterator=0;




              if(UART_ReadRxStatus()==UART_RX_STS_FIFO_NOTEMPTY ){










              if(UART_ReadTxStatus()==UART_TX_STS_FIFO_NOT_FULL ){







        • 1. Re: basic UART question

          Its not enough to just post code to get help, generally speaking.


          There are other issues that can affect troubleshooting, like HW


          setup, etc..








          Consider posting your project, makes life easier to troubleshoot.




          “File”                                                             Creator


          “Create Workspace Bundle”






          Regards, Dana.

          • 2. Re: basic UART question

             I just realised I posted this in the wrong subforum, meant to post this is PSoC 5, but the file is attached.


            Thanks for the timely reply.

            • 3. Re: basic UART question

              Do you get inside the while loop ?




              This has conflicting data types -




                  uint8 sendArray[4096];
                  uint8 receiveArray[4096];
                  int i;




              The pattern of 256 values in send array repeats 16 times because you declared it


              as uint8.




              Regards, Dana.

              • 4. Re: basic UART question

                You might also want to increase your heap size -














                The heap and stack size were reduced in 3.1, try restoring to 3.0 levels 4K and 16K respectively.


                3.1 default settings are now 128 bytes and 2K.




                Regards, Dana.

                • 5. Re: basic UART question

                   So, I applied the changes as suggested, it seems smart to do. The problem that I'm having is, my program runs up to the while loop, and stays in the loop since neither of my if statements meet their conditions, so the program never advances past the while loop. 


                  what I should ask is:
                  How does the status register update? shouldn't the status register of the UART automatically update?


                  for example if I'm reading the status register of the UART transmit, with it being intialized, but not used, shouldn't the follwing if statement evaluate to being true?








                  or am I approaching this idea from a wrong direction?

                  • 6. Re: basic UART question

                    I am stumped. If the Tx FIFO is full when you enter


                    the while, then nothing gets sent out. I looked at init


                    description, says nothing about clearing Tx FIFO, so


                    could it be full on startup ? Just a thought.




                    Maybe Bob can take a look at this. He knows quite a lot about


                    serial com.




                    Regards, Dana.

                    • 7. Re: basic UART question

                      Thank you, Dana. I'm a bit late today, we had a great italian dinner yesterday evening...


                      What first jumps to my mind: Interrupts should be enabled (usually).


                      There is an error: insert a #include <stdio.h>
                      to have sprintf() resolved.




                              if(UART_ReadTxStatus()==UART_TX_STS_FIFO_NOT_FULL ){


                      will fail: In the beginning, after initialization   UART_TX_STS_FIFO_EMPTY will be set, too so the result will never be equal to your questioned UART_TX_STS_FIFO_NOT_FULL.


                      Better use         if(UART_ReadTxStatus() & UART_TX_STS_FIFO_NOT_FULL ) which will be true, when the bit is set.


                      Same applies to _ReadRxStatus().


                      Lastly: in the embedded world you always hafe an infinite loop that repeats until powerr switched off. When your main() returns when reaching the end, do you know what will happen?


                      Better put an infinite loop at the end to wait or put the whole sending & revieving part into an infinite while-loop.




                      Happy coding



                      • 8. Re: basic UART question

                        I looked at UART Init code, several ap notes, cannot see where


                        FIFOs get cleared ? So do they startup with "junk in them ?




                        Regards, Dana.

                        • 9. Re: basic UART question

                          I trust in the underlying UDB or FF block will be cleared at initialization, I tested and after _Start() the FIFO flags show not full and empty, no errors set.





                          • 10. Re: basic UART question

                            I will post a case on this. No where in TRM, ap note on startup,


                            Datapath, etc.. does FIFO getting cleared stated.




                            Regards, Dana.