Anybody scanf working?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Anybody scanf working?

567 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by StephenHawkings on Sat Feb 26 08:27:28 MST 2011
Dear Collegues,
I'm trying now since some hours, to get the scanf function to work. printf is working fine.
In debug mode, after reaching the scanf line in my code, I tip in let's say 222, but after clicking Return, I'm ending up in the hartfault routine.
Does anybody have the scanf routine working?
Thank you!
0 Kudos
2 Replies

396 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by StephenHawkings on Sun Feb 27 04:01:32 MST 2011
Dear Collegues,
the trouble with scanf was my stack running out of memory.  So I've been shot to the hardfault routine.

Here is a working scanf / printf routine for purpose of debugging. System needs to be in semi-host mode.

I put in a line of code, to show how to use printf to get information out of CMSIS-declared variables and memory locations.
0 Kudos

396 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sat Feb 26 09:54:35 MST 2011
The fact that printf is working for you suggests that you are linking with the correct variant of the C library. Thus the most likely cause of your problems is that you are not calling scanf correctly. I suggest that you take a look at the following webpage and see if this helps you to spot the problem:

http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

Note that the usual cause of problems with scanf is passing a variable, rather than the address of the variable into scanf as a parameter.

If this does not get things working for you, then please post a compilable code snippet that shows up the problem. And please specify which MCU you are targetting (and confirm that you are using the latest LPCXpresso 3.6.2 (or 3.8.2 on Linux).

Regards
CodeRedSupport.
0 Kudos