scanf functionality in LPC1768

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

scanf functionality in LPC1768

11,135 次查看
emb02
Contributor IV

Hello, 

I want to use printf and scanf functions for LPC1768 controller in MCUXpresso IDE project.

I'm using - lpc17xx.cmsis.driver.library/blob/master/Drivers/source/debug_frmwrk.c to print data on UART terminal and I am able to print data on UART using printf.

But I'm not able to use scanf to get data from UART. I'm getting bus fault error while debugging.

Is there any project setting required to enable scanf?

Is there any example code for how to use scanf in LPC17xx?

 

I'm using MCUXpressoIDE_11.5.0.

 

Regards, 

EMB02

 

0 项奖励
回复
7 回复数

11,090 次查看
emb02
Contributor IV

Thank you for your response.

->An alternative would be to use the getkey() method of your debug_frmwrk.c source instead of scanf.

I'm using this and able to receive data from UART.

I'm attaching debug console library of LPC845 in which printf and scanf works properly.

->Not sure if you noticed, but printf/scanf  is not part of the debug_frmwrk.c source. 

So which library is used for printf/scanf for LPC17xx series? 

Regards, 

EMB02

0 项奖励
回复

11,086 次查看
frank_m
Senior Contributor III

> I'm using this and able to receive data from UART.
> I'm attaching debug console library of LPC845 in which printf and scanf works properly.

Not sure if that means you are using the LPC845 debug_* sources.
The fsl_*.c/h files are MCU specific, you would need those specific for the LPC176x.

> So which library is used for printf/scanf for LPC17xx series? 

I avoid clib functions in general, and printf/scanf in particular, for both code size and runtime issues.
In the rare instances I want or use direct serial interaction, I did the reception and parsing myself. I.e. receive up to a termination character ('\r','\n'), and convert an ASCII string to decimal or hexadecimal number.

For debugging, I often use the semihosting variant (usually only debug_printf), which comes in a special (semihosting) library. This is routed via the SWD/JTAG, works only with attached debugger, and is very likely not what you want.

If I remember correctly, older MCUs like the LPC176x variants lack the specific SDK support in the MCUXpresso IDE environment, as provided for newer one's (I use a LPC5462x).
I am not very familiar with the LPC176x in this setup, though.

0 项奖励
回复

11,061 次查看
emb02
Contributor IV

Hi,

->Not sure if that means you are using the LPC845 debug_* sources.

->The fsl_*.c/h files are MCU specific, you would need those specific for the LPC176x.

I'm not using LPC845 debug_* source files for LPC1768. 

I want that specific driver files which contains printf / scanf for LPC1768.

Is there any reference MCUXpresso project available for printf / scanf for LPC17xx series?

 

Regards,

EMB02

0 项奖励
回复

11,056 次查看
frank_m
Senior Contributor III

As said, I don't have LPC176X boards.

But have tried the projects that come preinstalled, like described here ?
 https://copperhilltech.com/blog/lpc17681769-arm-cortex-m3-development-mcuxpresso-ide-installation-an...

And the LPC-Open libraries ?
https://www.nxp.com/design/microcontrollers-developer-resources/lpcopen-libraries-and-examples:LPC-O...

 

0 项奖励
回复

11,107 次查看
emb02
Contributor IV

Hi,

Yes I know in scanf we have to pass address of the variable. I'm attaching test code.

I'm using CMSIS driver library.

I'm attaching library files used for printf and scanf.

 

Thank you.

0 项奖励
回复

11,096 次查看
frank_m
Senior Contributor III

As stated, I don't have your MCU platform available. But I never used standard CLib functions for serial input either.

In your situation, I would try to debug into the code, i.e. into the scanf() implementation. If necessary, into the assembler code. Note the values of registers involved in the instruction causing fault. And then relate it back to used variables.

Not sure if you noticed, but printf/scanf  is not part of the debug_frmwrk.c source. This is usually provided in a more generic clib implementation, that often requires you to implement the low-level UART code.

An alternative would be to use the getkey() method of your debug_frmwrk.c source instead of scanf.

0 项奖励
回复

11,113 次查看
frank_m
Senior Contributor III

I don't have a LPC1768 and the named driver library to try myself.

> But I'm not able to use scanf to get data from UART. I'm getting bus fault error while debugging.

Are you aware that scanf() requires the address of the variables that should accept the scanned value, not the variable itself ? In other words, passing by reference, not by value (like printf()).

The bus fault suggests you got that wrong.

Otherwise, I would check to source code of the low-level implementation underlying the prinf/scanf code of the library.

0 项奖励
回复