This is a trial (testing as per your instructions) Sorry for inconvenience #include #include volatile unsigned int tx_flag; //Mailbox Flag for the tx_char. volatile unsigned char tx_char; //This char is the most current char to go into the UART volatile unsigned int rx_flag; //Mailbox Flag for the rx_char. volatile unsigned char rx_char; //This char is the most current char to come out of the UART void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT UCA1CTL1 |= UCSWRST; // **Put state machine in reset** UCA1CTL1 |= UCSSEL_2; // SMCLK UCA1BR0 = 6; // 1MHz 9600 (see User's Guide) UCA1BR1 = 0; // 1MHz 9600 UCA1MCTL = UCBRS_0 + UCBRF_13 + UCOS16; // Modln UCBRSx=0, UCBRFx=0, UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine** UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt rx_flag = 0; //Set rx_flag to 0 tx_flag = 0; //Set tx_flag to 0 __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled //__no_operation(); // For debugger } /*uart_putc * Sends a char to the UART. Will wait if the UART is busy * INPUT: Char to send * RETURN: None */ void uart_putc(unsigned char c) { tx_char = c; //Put the char into the tx_char UCA1IE |= UCTXIE; //Enable USCI_A0 TX interrupt while(tx_flag == 1); //Have to wait for the TX buffer tx_flag = 1; //Reset the tx_flag return; }
↧