9 Replies Latest reply on Jan 8, 2017 8:47 AM by user_301665782

    Half Duplex Uart

    user_301665782

      Hi Everyone,

         

       

         

      I would need some help to implement an algorithm that let me send  through the PSoC 3'serial port  a few bytes  to  the serial port of device A  only every 5 seconds. That endless loop only can be interrupted if PSoc 3'serial port is receiving some few bytes from the device A.  Afterward  the endless loop should be running  again.

         

      Please see the attached file.

        • 1. Re: Half Duplex Uart
          user_1377889

          This is the main goal of an interrupt: to interrupt a running program.

             

          What I can see is that you are not using the APIs but accessing some registers directly, any special reasons for that?

             

          And strictly avoid any time consuming loops (as CyDelay()) in an interrupt handler.

             

          Next time, can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
          Creator->File->Create Workspace Bundle (minimal)
          and attach the resulting file. That will make checking the project easier because we can use the IDE.

             

           

             

          Bob

          • 2. Re: Half Duplex Uart
            user_301665782

             Hi Bob

               

            Thank so much for your answer.

               

            Before post my code so that I don't bother you,  please let me know the following:

               

            At the Uart 2.50 data sheet said:

               

            uint8 UART_ReadRxStatus(void) Description: Returns the current state of the receiver status

               

            "Side Effects:

               

            All status register bits are clear-on-read except UART_RX_STS_FIFO_NOTEMPTY.

               

            UART_RX_STS_FIFO_NOTEMPTY clears immediately after RX data register read.

               

            See the Registers section later in this datasheet. "

               

            What happened if  I need to use the  uint8 UART_GetChar(void) in place of  uint8 UART_ReadRxData(void) ?

               

            How should  I clear the  "UART_RX_STS_FIFO_NOTEMPTY"  bit  at the interrupt handler?

               

            I do not even see where the API "UART_GetRxInterruptSource()"  is at the Uart.h file and mentioned  at page 43 of the data sheet .

               

            Thank you in advance Bob

            • 3. Re: Half Duplex Uart
              user_1377889

              What happened if  I need to use the  uint8 UART_GetChar(void) in place of  uint8 UART_ReadRxData(void) ?

                 

              Always check for any characters received by UART_GetRxBuffersize() > 0 and then use GetChar() or ReadRxData().

                 

               

                 

              How should  I clear the  "UART_RX_STS_FIFO_NOTEMPTY"  bit  at the interrupt handler?

                 

              A NOTEMPTY cannot be cleared as long as there are chars in the fifo, use a while-loop in your handler to read all data from fifo.

                 

               

                 

              Easiest is:

                 

              increase the component's Rx and Tx buffers to something like 100 or 200. This will enable the components internal interrupts.

                 

              Use UART_GetRxBufferSize() to see if anything is received which you can check in your main loop.

                 

              I do not even see where the API "UART_GetRxInterruptSource()

                 

              There even is no such API anymore, the mentioning in the datasheet seems to be some remnants from former component versions. You'll need to check the status yourself.

                 

               

                 

              Bob

              • 4. Re: Half Duplex Uart
                user_301665782

                Thank you very much Bob.

                   

                Best regards,

                • 5. Re: Half Duplex Uart
                  user_301665782

                  Hi Bob

                     

                  I did as you suggest me in the last post.

                     

                  I mean, I have  increase the RX buffer to 10 and using internal RX interrupt.

                     

                  As you will see in the bundle the code has two section inside  the Forever loop.

                     

                  First  there is a simple message send through TX  I assume you will understand it.

                     

                  After some delay just for test,  you will find the RX code.

                     

                  The point is that  TX code and RX code cannot operate according to "Half Duplex mode" .

                     

                  If you comment the RX code, the TX code work OK  and vice versa is the same happen.

                     

                  The goal of this code is to test a WiFi breakout board  and specifically what is called web to serial App.

                     

                  Please see attached web page's screenshot   that I am using for testing.

                     

                  When you click on a color bar a string with color name is printed out on LCD of CY8KIT-030.

                     

                  When you send a message you will see it printed out in the gray box on the top right of the Web page.

                     

                  I am sure you will be able to clarify this for me  because I am missing something and I cannot figure it out what is it.

                     

                  Thank you very much in advance Bob.

                  • 6. Re: Half Duplex Uart
                    user_1377889

                    Your permanent switching between Rx and Tx mode spoils the expected result. The window where you may receive a byte is rather small.

                       

                    Question: What is the reason you don't use a full duplex UART?

                       

                     

                       

                    Bob

                    • 7. Re: Half Duplex Uart
                      user_301665782

                      You are right, I though it would be better use Rx and Tx only when  it would be needed.

                         

                      Here the Idea is to monitoring sensors periodically  to refresh the Web page.

                         

                      Also activate some actuators from the web page currently simulated  for the color bars as a way to send a command to the breakout board connected to PSoC.

                         

                      "The window where you may receive a byte is rather small." Do you refer to the Rx buffer?

                         

                      Tank you bob.

                      • 8. Re: Half Duplex Uart
                        user_1377889

                        Every time you switch the UART mode the current information gets lost, even when a byte is transmitted only half.

                           

                            UART_1_LoadRxConfig();   
                            while(UART_1_GetRxBufferSize()!=0)

                           


                        Imagine, the while loop sees no char in buffer, then you'll exit immediately and start over again. Since you just started to enable receive there is a pretty good chance for this scenario.

                           

                        Use full duplex, everybody does that. avoid longer CyDelays. When you want to time your main-loop use a timer. This will be independent of execution times.

                           

                        Lastly: Switch to PSoC5LP or PSoC4-M. Both are far more modern than the 40 year old design of the 8051. Prototype kits available for $10.

                           

                        Bob

                        1 of 1 people found this helpful
                        • 9. Re: Half Duplex Uart
                          user_301665782

                          Hi Bob

                             

                          Thank you Bob again.

                             

                          Yes , I followed your suggestion about  your " Question: What is the reason you don't use a full duplex UART?" and the code is already working OK just eliminating the UART_1_LoadTxConfig(); and UART_1_LoadRxConfig();

                             

                          On the other hand I have 1 PSoC 5LP Kit and 5 PSoC 5LP 049 kits testing the before sensor star network I have asked you for, so it was handy  to use 1  of the first 2 PSoC 3 kits I have purchased. Any way I will test the Full Dpx code on Psoc 5LP.

                             

                          I appreciate very much your help and for me it is an honor to receive help from someone who has the background you have.

                             

                          Thank you very much and have a great weekend.=)

                             

                          Alex