This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I'm working with ez430-rf2500. Now, I only can read a byte, how I could read more than one?
#include <msp430x22x4.h> ///////////////////7FUNCIONA Y ENVIA STRING BYTE A BYTE/////////////////////////// int i=0, a=0; int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; // Set DCO DCOCTL = CALDCO_1MHZ; P3SEL = BIT5; // USCI_A0 transmit data output (2274 to PC) UCA0CTL1 |= UCSSEL_2;; // CLK = SMCLK UCA0BR0 = 104; // 9600 bauds UCA0BR1 = 0; // 9600 bauds UCA0MCTL = UCBRS0; // Modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; // Enable USCI_A0 TX interrupt __bis_SR_register(LPM0_bits + GIE); // Enter LPM3, interrupts enabled } // USCI A0/B0 Receive ISR #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { a = UCA0RXBUF; }
You can go to the product page and download the code examples: http://www.ti.com/tool/ez430-rf2500
And/or download MSP430Ware here you will find also a lot of examples.
First you would need to know when the amount of bytes are done.
could be a length header,carriage return or zero terminated strings.
a[i] = UCA0RXBUF;
__bic_SR_register_on_exit(LPM0_bits);
if a[i]=13 /* carriage return sent */
{i=0; } /* kick start the main program back up*/
else
{i++}; /* recommend a check so it does not overflow buffer size */
Marcos, actually, you read as many bytes as are coming. But you always read them to the same variable a and you don’t tell anyone that a has got a new content.
Tony suggested one way to read multiple bytes, by reading them into a straight buffer with a known delimiter, and wake main when the delimiter was received.
Other options are a ring buffer in which the ISR writes, while main reads from it. The read and write pointers determine whether there is content to be read (or space to write). In this case, the incoming bytes are interpreted (including a delimiter, if any) by main, while the ISR is just receiving.
There are other ways too.
**Attention** This is a public forum