The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.
Defining a generic RS232 read and write function - ajellisuk - Aug 19 7:36:48 2009
Hi,
I have a project where I'm using an MSP430F449.
I have been using the RS232 port to send 24 bits data to a PC using the following
code:
TXBUF1=osc_volts;
while (!(IFG2 & UTXIFG1));
TXBUF1=osc_volts >> 8;
while (!(IFG2 & UTXIFG1));
TXBUF1=osc_volts>>16;
while (!(IFG2 & UTXIFG1));
(osc_volts is an unsigned long)
I would like to replace the above code with the following function:
void RS232_Write(char num_bytes, unsigned char *data)
{
do {
TXBUF1 = *data++;
while (!(IFG2 & UTXIFG1));
} while (--num_bytes);
}
Unfortuantly the compiler won't let me pass a long to the *data paremeter. How can I
create a generic function that will allow me to write any data type to the RS232 port?
Thanks in advance
Andrew
------------------------------------
______________________________
Have a look at the new TI MCU Center on EmbeddedRelated.com!
(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )
Re: Defining a generic RS232 read and write function - ajellisuk - Aug 19 9:19:59 2009
Hi again,
Sorry to waste bandwidth :(
I've just realized what I was doing wrong:
RS232_Write (3, (unsigned char *)&voltage);
This now works
Andrew
--- In m...@yahoogroups.com, "ajellisuk"
wrote:
>
> Hi,
>
> I have a project where I'm using an MSP430F449.
>
> I have been using the RS232 port to send 24 bits data to a PC using the following
code:
>
> TXBUF1=osc_volts;
> while (!(IFG2 & UTXIFG1));
> TXBUF1=osc_volts >> 8;
> while (!(IFG2 & UTXIFG1));
> TXBUF1=osc_volts>>16;
> while (!(IFG2 & UTXIFG1));
>
> (osc_volts is an unsigned long)
>
> I would like to replace the above code with the following function:
>
> void RS232_Write(char num_bytes, unsigned char *data)
> {
> do {
> TXBUF1 = *data++;
> while (!(IFG2 & UTXIFG1));
> } while (--num_bytes);
> }
>
> Unfortuantly the compiler won't let me pass a long to the *data paremeter. How can I
create a generic function that will allow me to write any data type to the RS232 port?
>
> Thanks in advance
>
> Andrew
>
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )Re: Defining a generic RS232 read and write function - tintronic - Aug 19 10:57:00 2009
Andrew,
Your question/problem had nothing to do with RS232, not even with the MSP430, but with the
C programming language.
Your second post actually doesn't answer the question you asked in the first one.
It would be smart for you to read the recently posted link
http://www.catb.org/~esr/faqs/smart-questions.html before you ask any other question on
any forum.
I think you can define your function like:
void RS232_Write(char num_bytes, void *data)
This link should help you adapt the rest of your function:
http://tigcc.ticalc.org/doc/keywords.html#void
Then, you should call it like this:
RS232_Write(sizeof(variable),&variable);
Regards,
Michael K.
--- In m...@yahoogroups.com, "ajellisuk"
wrote:
>
> Hi again,
>
> Sorry to waste bandwidth :(
>
> I've just realized what I was doing wrong:
>
> RS232_Write (3, (unsigned char *)&voltage);
>
> This now works
>
> Andrew
>
> --- In m...@yahoogroups.com, "ajellisuk" wrote:
> >
> > Hi,
> >
> > I have a project where I'm using an MSP430F449.
> >
> > I have been using the RS232 port to send 24 bits data to a PC using the following
code:
> >
> > TXBUF1=osc_volts;
> > while (!(IFG2 & UTXIFG1));
> > TXBUF1=osc_volts >> 8;
> > while (!(IFG2 & UTXIFG1));
> > TXBUF1=osc_volts>>16;
> > while (!(IFG2 & UTXIFG1));
> >
> > (osc_volts is an unsigned long)
> >
> > I would like to replace the above code with the following function:
> >
> > void RS232_Write(char num_bytes, unsigned char *data)
> > {
> > do {
> > TXBUF1 = *data++;
> > while (!(IFG2 & UTXIFG1));
> > } while (--num_bytes);
> > }
> >
> > Unfortuantly the compiler won't let me pass a long to the *data paremeter. How can I
create a generic function that will allow me to write any data type to the RS232 port?
> >
> > Thanks in advance
> >
> > Andrew
>
------------------------------------

(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )