EmbeddedRelated.com
Forums

Re: MSP430F1611 UART Receive Multiple Bytes From PC

Started by Gus Litovsky February 14, 2008
That is what I'm trying to do. It is like sending a packet. I don't want to receive any accidental data but well crafted data with a header.

----- Original Message ----
From: Paul Curtis
To: m...
Sent: Thursday, February 14, 2008 11:57:16 AM
Subject: RE: [msp430] MSP430F1611 UART Receive Multiple Bytes From PC

Hi,

> if(RXBUF0 == 0x42) // 0x42 is 'B'
> bgnCheck = 0x42;
> if(RXBUF0 == 0x47 &&bgnCheck == 0x42)
> bgnCheck = 0x47;
> if(RXBUF0 == ox4E && bgnCheck ==0x47)
> {
> bgnCheck = 0x10; // Header is received
> }
>
> So, pretty much what I expect (and did happen) was that the ISR will
> be called everytime there is a new character. if I send the word 'BGN'
> then first B will trigger the first if and then the ISR will end. the
> interrupt will be called again and then the second if will be called.
> The same with the third one.
>
> 1) Currently I'm even trying my old software, but all the MSP430 gets
> is the last character I send. that is, if I put a BP on :
> if(RXBUF0 == 0x42) // 0x42 is 'B' and send 'BGN'
>
> I'll see the 'N' which is the last byte in RXBUF0.
>
> 2) Does anyone have a better way of implementing something like this?

Oh. My. Gawd.

Just think about what you've written, what happens about seeing characters
you don't recognize in your BGN sequence, and what the UART is doing.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley. co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors







____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Beginning Microcontrollers with the MSP430

Hi,

> That is what I'm trying to do. It is like sending a packet. I don't
> want to receive any accidental data but well crafted data with a
> header.

Try looking up "Finite State Machine" to do matching. It's sort of what you
have, but yours looks like an ad-hoc fragile solution. And badly broken if
I look at the UART code. Really, really, consider why sequential reading of
RXBUF0 will do and what you need to do to avoid the problem.

So, I'm telling you that there are two distinct problems in your code. I've
given you hints. Treat this as a learning exercise as if I reel of the
solution you'll not learn why it works but cough it up using a learn-by-rote
method.

(Actually, most of our Asian-sounding brethren inhabiting this and the
LPC2000 group just want cut-and-dried solutions with somebody else taking
the strain of thinking about it, that's what I see...)

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors