Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Strange effects of UART at reset

Hello,

I use an UART peripheral to communicate with a computer. If I launch the program, it works correctly, but if I reset the Nios II processor I have some problems. Here I post an simpler example where I have also the problem. The first code works correctly all the time, I receive well 1234 each time I reset the cpu.

int main (void)
{
    printf("1234 ");
    while(1);
}

But if i had the usleep function, that works when I launch the program, but if I reset the cpu, it the programs sends more characters than wanted.

int main (void)
{
    usleep(500000);
    printf("1234 ");
    while(1);
}

I received the following (one line by reset of cpu) :

1234

34 1234

1234 1234

234 1234 1234

4 1234 1234 1234

1234 1234 1234 1234

34 1234 1234 1234 1234

But if I have the usleep function and I remove the while(1), I receive well 1234. Anybody have an idea why I have these effects ?

Thanks in advance.

Jérôme

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Do you still have the problem?

    If so, could you please confirm that you get longer output string ( by 3 characters or so ) string _each_ time you reset the CPU?

    At first, I thought that maybe the reset circuit had glitches and was causing the issue, but I think that would cause more random lengths, not consistently longer outputs...

    Also, you could look at the assembler output, it should be quite short ( at least for the main loop ).

    Also, you could try to change the compiler optimizer to a less optimized level.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Sorry for the late answer, I was not notifed. Yes the output strings was always longer by 3 characters after each reset.

    I noticed similar effect on others project I made. For example, I had a project where some global variables were initialized. And sometimes, after a reset, the variables were not initialized (keeping value before the reset).