EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Help for a beginner in MSP430

Started by Abhay June 28, 2011
Hi guys

I am beginner in MSP430 programming , i need few quick tips on coding .

firstly
how do I make my Code Composer Studio compatible with I/O statements specially "printf" I have tried every trick possible , increasing the heap/stack size well nothing worked out.

secondly can anyone point whats wrong in this piece of code
********************************************************
#include // header for MSP430f5528 device
#include
#include

char r_Lo,r_Hi;
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop WDT

MPY = 0x1234; // Load first operand -unsigned mult
OP2 = 0x5678; // Load second operand
__no_operation(); // For debugger
r_Lo = RESLO;
r_Hi = RESHI;

printf("Lower bits %x\n",r_Lo );
__bis_SR_register(LPM4_bits); // Enter LPM4
__no_operation(); // For debugger
}
*********************************************************8

Beginning Microcontrollers with the MSP430

Abhay wrote:
> Hi guys
>
> I am beginner in MSP430 programming , i need few quick tips on coding .
>
> firstly
> how do I make my Code Composer Studio compatible with I/O statements specially "printf" I have tried every trick possible , increasing the heap/stack size well nothing worked out.
>
> secondly can anyone point whats wrong in this piece of code
>

I've not been there with CCS but I'd guess you should be getting a
linker error without defining 'putchar( )'. Is that the case?

Best, Dan.

--
There are several traffic signs within the association. These signs are currently maintained by the city and are expected to have a useful life equal to the life of the community. They should only need to be replaced due to weather or vandalism and in the event that the city will no longer maintain the signs they will be budgeted for in the operation budget of the association. The condition of the signs at the time of the last field inspection was near new.

I'm sorry to inform you, but there is no printf for a microcontroller. However, you can do something like a serialPrint statement for an Arduino on a msp430. To do that, you will need to configure the UART to send serial messages at some baud rate where your computer can receive the message in a terminal program.

-Bear
--- In m..., "Abhay" wrote:
>
> Hi guys
>
> I am beginner in MSP430 programming , i need few quick tips on coding .
>
> firstly
> how do I make my Code Composer Studio compatible with I/O statements specially "printf" I have tried every trick possible , increasing the heap/stack size well nothing worked out.
>
> secondly can anyone point whats wrong in this piece of code
> ********************************************************
> #include // header for MSP430f5528 device
> #include
> #include char r_Lo,r_Hi;
> void main(void)
> {
> WDTCTL = WDTPW+WDTHOLD; // Stop WDT
>
> MPY = 0x1234; // Load first operand -unsigned mult
> OP2 = 0x5678; // Load second operand
> __no_operation(); // For debugger
> r_Lo = RESLO;
> r_Hi = RESHI;
>
> printf("Lower bits %x\n",r_Lo );
> __bis_SR_register(LPM4_bits); // Enter LPM4
> __no_operation(); // For debugger
> }
> *********************************************************8
>

I do not see anything wrong with your code.

"printf()" is a big high level Output routine and needs lower level support.

I do not use CCS, it is huge and supports all kinds of things that I do not ever use. Did it give you any clue of what was missing?

I use the little free KickStart, and it has no problem running your code.

--- In m..., "Abhay" wrote:
>
> Hi guys
>
> I am beginner in MSP430 programming , i need few quick tips on coding .
>
> firstly
> how do I make my Code Composer Studio compatible with I/O statements specially "printf" I have tried every trick possible , increasing the heap/stack size well nothing worked out.
>
> secondly can anyone point whats wrong in this piece of code
> ********************************************************
> #include // header for MSP430f5528 device
> #include
> #include char r_Lo,r_Hi;
> void main(void)
> {
> WDTCTL = WDTPW+WDTHOLD; // Stop WDT
>
> MPY = 0x1234; // Load first operand -unsigned mult
> OP2 = 0x5678; // Load second operand
> __no_operation(); // For debugger
> r_Lo = RESLO;
> r_Hi = RESHI;
>
> printf("Lower bits %x\n",r_Lo );
> __bis_SR_register(LPM4_bits); // Enter LPM4
> __no_operation(); // For debugger
> }
> *********************************************************8
>

i had the same problem when i started with the msp, reading c for dummies,
tried to start at the beginning [?]. Then I realized I needed some kind of
terminal connection... (as Bear kindly pointed out)

On Tue, Jun 28, 2011 at 3:18 PM, old_cow_yellow wrote:

> **
> I do not see anything wrong with your code.
>
> "printf()" is a big high level Output routine and needs lower level
> support.
>
> I do not use CCS, it is huge and supports all kinds of things that I do not
> ever use. Did it give you any clue of what was missing?
>
> I use the little free KickStart, and it has no problem running your code.
> --- In m..., "Abhay" wrote:
> >
> > Hi guys
> >
> > I am beginner in MSP430 programming , i need few quick tips on coding .
> >
> > firstly
> > how do I make my Code Composer Studio compatible with I/O statements
> specially "printf" I have tried every trick possible , increasing the
> heap/stack size well nothing worked out.
> >
> > secondly can anyone point whats wrong in this piece of code
> >
> >
> > ********************************************************
> > #include // header for MSP430f5528 device
> > #include
> > #include
> >
> > char r_Lo,r_Hi;
> > void main(void)
> > {
> > WDTCTL = WDTPW+WDTHOLD; // Stop WDT
> >
> > MPY = 0x1234; // Load first operand -unsigned mult
> > OP2 = 0x5678; // Load second operand
> > __no_operation(); // For debugger
> > r_Lo = RESLO;
> > r_Hi = RESHI;
> >
> > printf("Lower bits %x\n",r_Lo );
> > __bis_SR_register(LPM4_bits); // Enter LPM4
> > __no_operation(); // For debugger
> > }
> > *********************************************************8
> >
>


Ken Bueltmann wrote:
> i had the same problem when i started with the msp, reading c for dummies,
> tried to start at the beginning [?]. Then I realized I needed some kind of
> terminal connection... (as Bear kindly pointed out)
>

Hi Ken, ocy,

As I recall kickstart would get you a linker error if you don't define
putchar, (don't see how it wouldn't.). I use GCC, you have to define
putchar. But there certainly is a printf in the stdio, that is not a
micro thing. What is the issue is that the msp430 libs don't come with
an operating system (i.e,i/o), so, no putchar. The author has to supply
that.

Best, Dan.

--
There are several traffic signs within the association. These signs are currently maintained by the city and are expected to have a useful life equal to the life of the community. They should only need to be replaced due to weather or vandalism and in the event that the city will no longer maintain the signs they will be budgeted for in the operation budget of the association. The condition of the signs at the time of the last field inspection was near new.

On 28.06.2011 16:34, Abhay wrote:
:
> how do I make my Code Composer Studio compatible with I/O statements specially "printf" I have tried every trick possible , increasing the heap/stack size well nothing worked out.
:

There is a description in slau132 (7.2 The C I/O Functions) how to
implement printf() for your environment.

Because that is rather complicated I'm preferring to define my own
printf() functions:
static int _outc( char c, void *_op )
{
// send character to your I/O device
return 1;
} // _outc

static int _outs( char *s, void *_op )
{
size_t n;
size_t len = strlen( s );

for (n = 0; n < len; ++n) {
_outc( *s, _op );
++s;
}

return (int)len;
} // _outs

void Debug_printf( const char *fmt, ... )
{
va_list _ap;

va_start( _ap, fmt );
_printfi_nofloat( &fmt, _ap, NULL, _outc, _outs);
va_end( _ap );
} // Debug_printf
After that calling Debug_printf() should serve your needs (don't forget
device initialization of course).

Another pitfall for 'beginners' with CCS is, that it does not initialize
globals/statics to zero. To do this you have to define something like:

int _system_pre_init( void )
{
extern uint8_t __bss__;

memset( &__bss__, 0, &_stack - &__bss__ );

_register_lock( _nop );
_register_unlock( _nop );

return 1;
} // _system_pre_init

Good luck.

Hardy
Dan,

You are right. With KickStart, normally printf() will call putchar() which in turn will call __write() to send characters to an I/O terminal. But __write() is not in the library.

However, the debugger has an I/O terminal emulator. If you enable that feature, part of the PC screen and keyboard will act as fake I/O terminal for the MSP430.

--OCY

--- In m..., Dan Bloomquist wrote:
>
> Ken Bueltmann wrote:
> > i had the same problem when i started with the msp, reading c for dummies,
> > tried to start at the beginning [?]. Then I realized I needed some kind of
> > terminal connection... (as Bear kindly pointed out)
> >
>
> Hi Ken, ocy,
>
> As I recall kickstart would get you a linker error if you don't define
> putchar, (don't see how it wouldn't.). I use GCC, you have to define
> putchar. But there certainly is a printf in the stdio, that is not a
> micro thing. What is the issue is that the msp430 libs don't come with
> an operating system (i.e,i/o), so, no putchar. The author has to supply
> that.
>
> Best, Dan.
>
> --
> There are several traffic signs within the association. These signs are currently maintained by the city and are expected to have a useful life equal to the life of the community. They should only need to be replaced due to weather or vandalism and in the event that the city will no longer maintain the signs they will be budgeted for in the operation budget of the association. The condition of the signs at the time of the last field inspection was near new.
>

Hi All,
I use sprintf(buffer,"%3u",value); to get an int into a string so I can
easily print them onto my LCD (I use CCS). To make sprintf() work you have
to go to properties of your project in the "C/C++ build" tab go to "Library
Assumption" on the list that pops up when you select C/C++ build. Once you
have clicked on the Library assumption there is an option (should be the
first one) that reads "Level of printf support required(--printf support)"
turn this to full and there you go. If you really need a pic of it I can
post one but I am rather lazy and you should be able to figure it out.

Jake G

On Wed, Jun 29, 2011 at 12:14 AM, old_cow_yellow
wrote:

> **
> Dan,
>
> You are right. With KickStart, normally printf() will call putchar() which
> in turn will call __write() to send characters to an I/O terminal. But
> __write() is not in the library.
>
> However, the debugger has an I/O terminal emulator. If you enable that
> feature, part of the PC screen and keyboard will act as fake I/O terminal
> for the MSP430.
>
> --OCY
> --- In m..., Dan Bloomquist wrote:
> >
> > Ken Bueltmann wrote:
> > > i had the same problem when i started with the msp, reading c for
> dummies,
> > > tried to start at the beginning [?]. Then I realized I needed some kind
> of
> > > terminal connection... (as Bear kindly pointed out)
> > >
> >
> > Hi Ken, ocy,
> >
> > As I recall kickstart would get you a linker error if you don't define
> > putchar, (don't see how it wouldn't.). I use GCC, you have to define
> > putchar. But there certainly is a printf in the stdio, that is not a
> > micro thing. What is the issue is that the msp430 libs don't come with
> > an operating system (i.e,i/o), so, no putchar. The author has to supply
> > that.
> >
> > Best, Dan.
> >
> > --
> > There are several traffic signs within the association. These signs are
> currently maintained by the city and are expected to have a useful life
> equal to the life of the community. They should only need to be replaced due
> to weather or vandalism and in the event that the city will no longer
> maintain the signs they will be budgeted for in the operation budget of the
> association. The condition of the signs at the time of the last field
> inspection was near new.
> >
>

--
Thomas J. Grajewski
Engineer


From what I can remember, in CCS4 there is a dialogue in the project settings that governs how much 'printf' support the compiler offers, none, a little or full support. Default is none.

--- In m..., "Abhay" wrote:
>
> Hi guys
>
> I am beginner in MSP430 programming , i need few quick tips on coding .
>
> firstly
> how do I make my Code Composer Studio compatible with I/O statements specially "printf" I have tried every trick possible , increasing the heap/stack size well nothing worked out.
>
> secondly can anyone point whats wrong in this piece of code
> ********************************************************
> #include // header for MSP430f5528 device
> #include
> #include char r_Lo,r_Hi;
> void main(void)
> {
> WDTCTL = WDTPW+WDTHOLD; // Stop WDT
>
> MPY = 0x1234; // Load first operand -unsigned mult
> OP2 = 0x5678; // Load second operand
> __no_operation(); // For debugger
> r_Lo = RESLO;
> r_Hi = RESHI;
>
> printf("Lower bits %x\n",r_Lo );
> __bis_SR_register(LPM4_bits); // Enter LPM4
> __no_operation(); // For debugger
> }
> *********************************************************8
>


The 2024 Embedded Online Conference