| Details |
Message |
|
Read-Only
Author Gudjon Gudjonsson
Posted 13-Jul-2009 11:39 GMT
Toolset ARM
|
 lpc2103 sprintf problem
Gudjon Gudjonsson
Hi I do have problems with the sprintf function and the Keil
compiler. The program works nicely until I increase the amount of
functions, even if I don't use them. First I get the
"%02d,%d"
into the buffer if I define one extra function but the program stops
working if I define more functions.
I made my own, incomplete sprintf function and then it works
perfectly.
I have tried to play the size of the following parameters in the
Startup.s file:
USR_Stack_Size EQU 0x00000400
Heap_Size EQU 0x00000400
but without any success.
If anyone has any clue I would be very thankful.
Regards
Gudjon
|
|
|
Read-Only
Author Gudjon Gudjonsson
Posted 14-Jul-2009 20:18 GMT
Toolset ARM
|
 RE: lpc2103 sprintf problem
Gudjon Gudjonsson
The problem is solved but I don't know what I did (if anything) to
solve it. Now it works with cstack=0x200 and heap=0x200.
Regards
Gudjon
|
|
|
Read-Only
Author Hans-Bernhard Broeker
Posted 14-Jul-2009 21:01 GMT
Toolset ARM
|
 RE: lpc2103 sprintf problem
Hans-Bernhard Broeker
The problem is solved but I don't know what I did (if anything)
to solve it.
Then it's not solved --- it just disappeared. If you don't know
how you fixed it, you didn't.
|
|
|
Read-Only
Author Gudjon Gudjonsson
Posted 14-Jul-2009 21:38 GMT
Toolset ARM
|
 RE: lpc2103 sprintf problem
Gudjon Gudjonsson
Hi Hans, your name sounds familiar are you a Debian-Linux
user?
I can spend some time on trying to reproduce the problem if you are
interested. I was running Keil under Wine on my Linux box and it may
have had something to do with CRLF line endings. Today I got my JTAG
connector so I moved the code to Windows and then it worked. When I
compiled it again under Linux, it worked too. Other possible reason
is that I made a mistake in the interrupt routine that I have fixed
now. I had however commented the interrupt routine out and all
related parameters but I may have missed something out. The problem
has disappeared, I don't know the reason but if it doesn't appear
again, I'm happy :) But do you know if it is possible to run the JTAG
connector under Linux?
Regards
Gudjon
|
|
|
Read-Only
Author Gudjon Gudjonsson
Posted 15-Jul-2009 13:40 GMT
Toolset ARM
|
 RE: lpc2103 sprintf problem
Gudjon Gudjonsson
Well, my conclusions above were incorrect. Using sprintf just
gives me unpredictable results if I try to format integers. Sometimes
it works sometimes not. It seems to work nicely when I use it for
constant character arrays at least.
I will close the thread if I find the real problem sometime.
|
|
|
Read-Only
Author Tamir Michael
Posted 15-Jul-2009 14:12 GMT
Toolset ARM
|
 RE: lpc2103 sprintf problem
Tamir Michael
your stack requirements will grow significantly if you have nested
calls to functions such as sprintf.
the program stops working if I define more functions.
exception? what is the value of R14, if so?
|
|
|
Read-Only
Author Gudjon Gudjonsson
Posted 15-Jul-2009 23:00 GMT
Toolset ARM
|
 RE: lpc2103 sprintf problem
Gudjon Gudjonsson
Hi Tamir
Thanks for the answer. I don't have any nested calls to sprintf.
The main loop of the code looks like this (a bit simplified):
int
main ()
{
char buf[30];
char fname[30];
unsigned char ch;
Initialize ();
UART0Initialize (57600);
UART1Initialize (57600);
CCR=0x11;
T1TCR = 0x1;
while (1)
{
ch=UART0ReadChar_nostop ();
if (ch=='g')
{
sprintf(buf,"%04d.%02d.%02d %02d:%02d:%02d\r\n",(int) YEAR , (int) MONTH, (int) DOM, (int) HOUR, (int) MIN, (int) SEC);
UART0WriteString((unsigned char *) buf);
if (0==VNC1L_DiskPresent ())
{
sprintf(fname, "%02d%02d%02d%02d.dat",((int) YEAR%100), (int) MONTH, (int) DOM, (int) HOUR);
VNC1L_FileOpenWrite((unsigned char*) fname);
VNC1L_FileWrite(buf);
VNC1L_FileClose((unsigned char*) fname);
VNC1L_SuspendMonitor();
UART0WriteString((unsigned char *) fname);
} else {
sprintf(buf,"No disk found\n");
UART0WriteString((unsigned char *) buf);
}
}
}
}
Then I added a very simple function definition without using it and
the code stops working.
When you ask for the value of R14, is it during the call to
sprintf you mean? I have to admit that I had some difficulties
debugging that portion.
I think I will have to live with my tiny_sprintf function until I
get more familiar with the microcontroller.
Regards
Gudjon
|
|
|
Read-Only
Author Tamir Michael
Posted 16-Jul-2009 07:02 GMT
Toolset ARM
|
 RE: lpc2103 sprintf problem
Tamir Michael
what do you mean by "the program stops working"? does your
processor enter an exception mode? if so, you can try to figure out
what the last instruction executed was before the exception by
looking at R14 minus 8 (when in abort or under exception modes). if
no exception occurs - what does happen? again, what does "stops
working" mean?
|
|