USBUART code issue

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

cross mob
lock attach
Attachments are accessible only for community members.
AjBa_3976296
Level 2
Level 2
5 likes given First like received First like given

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

0 Likes
1 Solution

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 "CY8CK...

Regards,

Noriaki

View solution in original post

13 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

0 Likes

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.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

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

0 Likes

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​ !

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 "CY8CK...

Regards,

Noriaki

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.

0 Likes

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

0 Likes

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.

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,

I modified Noriaki-san's sample with SysTick.

It seems to be working.

moto

0 Likes
lock attach
Attachments are accessible only for community members.
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

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

Regards,

Noriaki

Thanks Noriaki!

I will test it and let you know.