Other Parts Discussed in Thread: MSP430G2553
Hi, everyone , I want to transmit many strings to my computer super terminal by msp430g2553, I can send and receive data with TI example code (“msp430g2xx3_uscia0_uart_06_9600),but it sends one string to PC by UART. I want to make subroutine to send many string , my code:
#include "msp430g2553.h"
char string1[]={"||**Hello world^_^**||\n\n\r"};
char string2[]={"You are right\n\r"};
char string3[]={"Thank you!\n\r"};
char string4[]={"Good luck \n\r"};
void send(char []);
unsigned int i;
char string[];
char *var;
void send(char string[])
{
var=string;
i = 0;
IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt
UCA0TXBUF = var[i++];
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR = 0xFF; // All P1.x outputs
P1OUT = 0; // All P1.x reset
P2DIR = 0xFF; // All P2.x outputs
P2OUT = 0; // All P2.x reset
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P3DIR = 0xFF; // All P3.x outputs
P3OUT = 0; // All P3.x reset
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 0x03; // 32kHz/9600 = 3.41
UCA0BR1 = 0x00; //
UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
_EINT();
send(string1);
send(string2);
send(string3);
send(string4);
//_DINT();
while(1);
}
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
UCA0TXBUF = var[i++]; // TX next character
if (i == sizeof var - 1) // TX over?
IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt
}
My question is as follow:
(1) when I did not add //_DINT(); the msp430 did not stop sending data to super terminal, the PC receive data is messy code. My target is that msp430 send string1[]~string4[] and stop , but the process did not follow order.
(2) when I add //_DINT(); to code, the super terminal only receive one byte and is not right. I don’t know where the problem
(3)Did there have many examples to send string by subroutine?
Thank you very much for your answers!