Topic : scanf failure

Forum : 8051

Original Post
Post Information Post
February 14, 2008 - 2:41pm
Guest

Using build 747-51 for the upsd3400

Just started a new project after not using the Ride for a year or so. The following fails

static char EncStr[ 40 ];

void ProcessEncoder(void )
{
unsigned int a,i;
...
for (i = 0 ; i < 40; i++)
EncStr[i] = 0;

a = 1;
sprintf( &EncStr[0] ,"test %d", a);
...

}

What I get in the buffer is "test " followed by the character '6' 255 times. I have tried a variety of options and always get the '6'. I have increased the (s)print buffer size in the linker options to 64 so its bigger than the EncStr.

This is no different that commands I have used in previous projects, so has there been a change in the compiler??

Replies
Post Information Post
+1
0
-1
February 18, 2008 - 5:57pm
Guest

Check in "Options | Project | LX51 | Linker | (s)printf buffer size".
The default value is '16' and there is no problem when running your simple program.
The behaviour you described could be produced by changing the default by '0' for example. Keep '16' and it should work.
Let me know if the problem is there. Thanks.

+1
0
-1
February 19, 2008 - 3:13pm
Guest

Regret this didn't work.

I have sent you the project file direct.

+1
0
-1
February 19, 2008 - 4:33pm
Guest

I started your application in simulation, and after the initialization, I set PC = the line where the sprintf is coded. It works as expected in simulation (both the sprintf and the write_page function that follows).
Therefore I guess that you have:
1. Either a problem with LCD display,
2. Or a issue with interrupt that I do not reproduce here in simulation.

+1
0
-1
February 20, 2008 - 11:34am
Guest

Problem identified in discussion with Francis Lamotte.

The project used the LARGE model and I had specified external stack.

There is some slightly contradictory advice if you click Help in Options/Project/RC51 on the Memory Model page. It starts by saying
“it is necessary to use an external stack (in xdata) for LARGE, COMPACT or HUGE model applications”
and goes on to state
“However, external stack use for SMALL, COMPACT and LARGE models is optional.”

Buried in the startup.a51 file is a commentfrom ST that states
;-------------------------------------------------------------------------------
; 9. If selected, initialize the external stack.
;-------------------------------------------------------------------------------
; For uPSD33xx and uPSD34xx DO NOT USE THE EXTERNAL STACK!!!!
;-------------------------------------------------------------------------------

i.e. it doesn't work.

de-selecting it and scanf works. Wounder what else didn't?

+1
0
-1
February 20, 2008 - 12:00pm
Guest

More information about this issue:
The external stack is located in the "pdata" space (using MOVX @Ri instructions). For most of the 8051 derivatives, the pdata MSB address is defined by the value stored in the P2 latch. For some specific devices, P2-latch is replaced by either a fixed value (FF or 00) , for some others, it is replaced by s specific SFR. This is normally well managed by the linker (startup selection and configuration). In the case of the uPST33xx and uPSD34xx, the pdata (MOVX @Ri instructions) is NOT supported by the device. Therefore, the external stack is NOT supported. We will document this more precisely.