13 Replies Latest reply on Jul 15, 2020 9:23 PM by MoTa_728816

    USBUART code issue

    AjBa_3976296

      I'm using a PSOC 5LP.

      This code works..

      for(;;)

          {

           if (LightItUp_Read() != lightState)

              {

                  lightState = LightItUp_Read();

                  if (lightState)

                      DebugPort_PutString("Light On\r\n");

                  else

                      DebugPort_PutString("Light Off\r\n");

              }

          }

       

       

      But this doesn't..

      for(;;)

          {

                  lightState = LightItUp_Read();

                  if (lightState)

                      DebugPort_PutString("Light On\r\n");

                  else

                      DebugPort_PutString("Light Off\r\n");

              CyDelay(1000);

          }

       

      Can someone please explain ?

       

      Message was edited by: Ajinkya Bansod Added new project

        • 1. Re: USBUART code issue
          MoTa_728816

          Hi,

           

          Would you explain what you mean by "works" and "doesn't"?

          (1) It does not even compile?

          (2) Does it stall or crash the program at some point?

          (3) Does it run but no output displayed?

          (4) Does it run but only one type of output displayed?

           

          It would be nice if you can attach an archive of the project or sample project

          which we can reproduce the problem.

          Please refer to the following discussion about about how to attache a project.

          How to attach a project archive file to a question?

           

          moto

          • 2. Re: USBUART code issue
            NoriakiT_91

            I have confirmed both code will work.  Please refer attached project example using the CY8CKIT-059 prototyping kit.

             

            Regards,

            Noriaki

            1 of 1 people found this helpful
            • 3. Re: USBUART code issue
              MoTa_728816

              Hi,

               

              Having written my previous response,

              I would try to check following things.

               

              Are they different projects or just changing source in the same project?

              (1) If they are different projects.

              I would copy the working project to another name and copy only the different part of the "not working" source and try it.

               

              (2) If they are the same project. (Only the source is modified) the only difference I could notice was

              the number of LightItUp_Read() calls.

              When it is working the function is called twice.

              When it does not it is being called only once.

              I wonder if you try

              =================

              for(;;)

                  {

                          lightState = LightItUp_Read(); /* to avoid this line to be optimized, please add volatile to the difinition of lightState */

                          lightState = LightItUp_Read();

                          if (lightState)

                              DebugPort_PutString("Light On\r\n");

                          else

                              DebugPort_PutString("Light Off\r\n");

                      CyDelay(1000);

                  }

              =================

               

              moto

              • 4. Re: USBUART code issue
                AjBa_3976296

                By "doesn't work" I mean no data is displayed on serial terminal of computer.

                I can't find anything to upload rar here. This is my whole code.

                 

                #include "project.h"

                 

                 

                int main(void)

                {

                    CyGlobalIntEnable; /* Enable global interrupts. */

                    uint8 lightState = 0;

                 

                 

                    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

                    DebugPort_Start(0, DebugPort_5V_OPERATION);

                 

                 

                    for(;;)

                    {

                        /* Place your application code here. */

                        //if (LightItUp_Read() != lightState)

                        {

                            lightState = LightItUp_Read();

                            if (lightState)

                                DebugPort_PutString("Light On\r\n");

                            else

                                DebugPort_PutString("Light Off\r\n");

                        }

                        CyDelay(1000);

                    }

                }

                 

                 

                Thanks for giving your precious time to help the community.

                • 5. Re: USBUART code issue
                  AjBa_3976296

                  Thanks Noriaki!

                  I will test it and let you know.

                  • 6. Re: USBUART code issue
                    MoTa_728816

                    Hi,

                     

                    > By "doesn't work" I mean no data is displayed on serial terminal of computer.

                    OK, thank you for the answer.

                     

                    I have a couple of questions.

                    (1) What is your development environment? (PSoC Creator, MDK Keil, IAR EWARM or something else?)

                    (2) What component is "LightItUp"? GPIO input, or something else?

                     

                    > I can't find anything to upload rar here. This is my whole code.

                    Have you checked the link?

                    How to attach a project archive file to a question?

                     

                    If you are using a PSoC Creator there should be many more files to be archived to reproduce "your project"

                     

                    Meantime, have you had chance to download and test NoriakiT_91-san's sample(s)?

                     

                    moto

                     

                    • 7. Re: USBUART code issue
                      AjBa_3976296

                      Ok.. Thanks for the info.

                      I've attached project.

                      What I need is a basic USBUART to output debug info via USB to computer. But when I try to periodically send data, I don't get data on terminal

                      • 8. Re: USBUART code issue
                        AjBa_3976296

                        Hi!

                         

                        I'm using PSOC creator. Lightitup is my LED status.

                         

                        I just tested Noriaki's sample. It works fine. My mistake was I wasn't waiting for USB to complete initialization as done by Mr Noriaki. I added that part to my code and it works fine.Thanks NoriakiT_91 and MoTa_728816 !

                        1 of 1 people found this helpful
                        • 9. Re: USBUART code issue
                          NoriakiT_91

                          If you want to use the USBUART as a logging, it is better to implement a FIFO.

                           

                          Please let me introduce my repository on github.  In the project example FIFOs are implemented to the TX and RX of USBUART.

                           

                          GitHub - noritan/Design307: FIFO Implementation for USBUART for BLOG - "CY8C5888LTI-LP097" on "CY8CKIT-059"

                           

                          Regards,

                          Noriaki

                          1 of 1 people found this helpful
                          • 10. Re: USBUART code issue
                            AjBa_3976296

                            Hey Noriaki!

                            I used the FIFO USBUART code with my I2C code and it worked fantastically.

                            Now I'm trying to use Systicktimer with it and it is causing issues.

                            Does USB timer and Systicktimer clash?

                             

                            I tried to debug but the code gets stopped at

                                    // Wait for initialization completed

                                    while (USBUART_GetConfiguration() == 0);

                            The initialization never completes and code gets stuck at this while loop.

                            I have attached the project to question.

                            Please guide.

                            • 11. Re: USBUART code issue
                              AjBa_3976296

                              Hey Motoo!

                              I used the FIFO USBUART code with my I2C code and it worked fantastically.

                              Now I'm trying to use Systicktimer with it and it is causing issues.

                              I have attached the project to question.

                              Does USB timer and Systicktimer clash?

                               

                              I tried to debug but the code gets stopped at

                                      // Wait for initialization completed

                                      while (USBUART_GetConfiguration() == 0);

                              The initialization never completes and code gets stuck at this while loop.

                              Please guide.

                               

                               

                              • 12. Re: USBUART code issue
                                NoriakiT_91

                                If you have any trouble to USB when the systick timer is used,  it is supposed that the Interrupt Service Routine (ISR) for the SysTick timer consumes CPU for long time.

                                 

                                Because the SysTick timer's priority is very high, please reduce the required time in that ISR.

                                Please check if there is a loop in the ISR waiting fro external events.

                                 

                                Regards,

                                Noriaki

                                • 13. Re: USBUART code issue
                                  MoTa_728816

                                  Hi,

                                   

                                  I modified Noriaki-san's sample with SysTick.

                                  It seems to be working.

                                   

                                  moto