Log in

View Full Version : Printf acting flaky


steven114
15-02-2005, 20:51
I'm having a few issues with calling printf - it sometimes leaves the format string (like %d) in the output. Something like this:

joyx = 127
joyx = 127
joyx = 127
joyx = %d
joyx = 127
etc...

It seems to be random.

Also, it doesn't seem to like to have information pushed at it multiple times through the main loop. Even though I push a \r\n at it (although the same thing happens with either \r or \n) it overwrites the last bit of output. Is there a buffer or something that can hold a limited amount of data? I never experienced any problems like this last year - did something change? I'm sorry if this seems like a trivial problem - but it's driving me absolutely insane.

gnormhurst
16-02-2005, 12:08
I had similar problems last year with printf outputs (using printf_lib). This began after I started using Kevin Watson's tracker code.

The problem was solved by modifying a #pragma statement to cause the compiler to save more processor context prior to servicing an interrupt (the trackers used interrupts to process the IR beacons).

Are you using interrupts? Like wheel encoders?

-norm

Joel J
16-02-2005, 12:30
What additional contexts? Right now I'm saving PROD, MATH_DATA, and .tmpdata .

steven114
16-02-2005, 19:47
I'm using a few timer interrupts currently (although not TMR0) and will be using digital input interrupts too.

What else should I save?

Joe Ross
20-02-2005, 11:54
Also, how often are you printing stuff, and how many characters. What is your interrupt rate? What serial drivers are you using?

steven114
20-02-2005, 12:52
I'm printing stuff once every 15 data packets (26.2*15=393 so about every .4 seconds) and it's about twenty-ish characters long. The only interrupt firing right now is the timer 1 overflow interrupt. I'm not using the TTL serial port, and I haven't fiddled with whatever code comes as default for printf.

Mark McLeod
20-02-2005, 14:02
joyx = 127
joyx = 127
joyx = %d
joyx = 127
etc...
This is a little too flaky for my taste.
Is this from a single printf statement or do you have two identical printf statements printing results in separate spots? The simplest explaination would be two similar printf's, but one with a typo like: printf("joyx = %d\r");

steven114
20-02-2005, 19:20
Same printf.