EmbeddedRelated.com
Forums

Printf() function problem

Started by Erdi July 16, 2009
Hi,I am using msp430f248 and trying to implement printf() function on my embedded system. I have my own functions that can successfully send or receive data from UART0. But i can not use printf() function so I have done a few things which i searched from the forum of TI, e2e community, and those things are below. By the way, i am using CCE 3.1.
1. Extract the .zip file “/tools/compiler/MSP430/lib/rtssrc.zip” into a folder on your harddrive.2. Add the files fputc.c and fputs.c in the extracted /SHARED/ directory to your CCE project. fputc( ) is called for the characters in the printf( ) function . fputs( ) is called for the '%x' strings in the printf function.3. Edit the fputc and fputs functions to fit your needs (e.g.- poll TXIFG and load transmit buffer). Your printf function is now ported.4. Check the project settings so that the linker will not return any errors. The CCE v3 version will return "symbol redefined" errors when custom runtime source files are added to the project. To get around these errors, do the following: Project Properties->C/C++ Build->MSP430 Linker: Change the Command line pattern to be: ${command} ${inputs} ${flags} ${output_flag}${output} Placing ${inputs} before ${flags} puts the object files before the runtime library on the link command line, thus resolving the
reference to the definition in the object file. Now rebuilding the project should no longer generate the symbol redefined errors.5. Increase the heap size to ~500 bytes under the menu option: Project--> Properties--> C/C++ Build -->Tool Settings-->Runtime environment. Printf is a huge function and requires quite a lot of heap space.
After doing those above, i have a semi successfull printf() function working. It is not absolutely successfully working because it can not format the thing i want to write. For example; i am trying to write both a character and a formatted integer but it can not format the integer. The code is as below;int y=50;printf("a%d\r\n",y);--------- and that writes only "a" on the console but not the formatted integer. What should i do to solve this in addition to the things mentioned above?




Beginning Microcontrollers with the MSP430