cancel
Showing results for 
Search instead for 
Did you mean: 

Scanf with Nucleo-F401RE & STM Eclipse C IDE

kai23
Associate
Posted on November 25, 2016 at 12:23

Hello,

first i have to say, i´m a bloody Beginner with C and STM.

Never the less, i have the following problem.

I just want do make it possible to communicate with Terminal (Putty, Terra Term,...).

Printf seems to work, there is a good example in Cubemx.

But scanf is not working. Whatever i try, my program is not able to process the input. As well at the Terminal there is no input seen unless i activate ''local echo'' at the terminal.

I have tried different example code, sometimes the programm stucks in my while loop and is waiting for an input. And without while loop, the input is skipped.

I´m nearly sure this depends on Getchar_Prototype but for me, it is still not clear what i have to do.

Maybe someone could help or knows some good online Tutorials/Books.

Thanks Kai
5 REPLIES 5
Posted on November 26, 2016 at 00:40

You'll probably find most embedded solutions don't use scanf() as the primary means of input. Think about managing the input/output more directly, and use sscanf() on the string to get from that.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 26, 2016 at 06:21

Wait, I think I might know this one; I have seen that some of the compiler/libraries (newlib) use buffering on input.

Try holding down a key on your keyboard for about 210 seconds. I seem to remember that the buffer was about 2K and you get about 10 characters per second off of a keyboard.

Just a shot in the dark.
Posted on November 26, 2016 at 06:34

Kay, found it. The compiler was gcc from sw4stm32 (ac6). The buffer was 1024 characters, and the command to turn off buffering is:

.ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 p.p1 {margin:0.0px 0.0px 0.0px 0.0px;font:12.0px 'Courier New';} .ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 span.s1 {;} .ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 span.s2 {color:#793d93;} .ExternalClassCE8F3B77326446E0B6CCD68E5AF37C27 span.Apple-tab-span {white-space:pre;}

setvbuf

(stdin, NULL, _IONBF, 0);

Put this in your program somewhere before your big loop.
kai23
Associate
Posted on November 28, 2016 at 10:07

Many thanks, this is what i was searching for :-)

It works now.

That was not easy for a beginner like me.

Kaily

Posted on November 28, 2016 at 20:49

No, that definitely isn't your fault. I taught an intro to embedded systems class at the local maker space and this came up when I was teaching the UART section.

I'm doing a brain dump of my course notes on the Embedded.FM blog (embedded.fm/blog) and this week's topic is - UARTs.

I will be giving you this tidbit in about two weeks. There's quite a bit to go over yet.

I'm glad I could help.

Andrei from The Great White North

(as seen on the embedded.fm podcast and blog)