Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 22733

MSP430FR5949 Can not get UART A1 to work, A0 works fine

$
0
0

I am having a bit of a confusing issue. I got my UART A0 to work just fine (Thanks Akash!). However when I try to enable the second UART (A1), nothing works, even with the same settings! (Except of course, the P2SEL bits). A1 also will not work on its own, with the same settings as A0. How do I get A2 to work. My code is below.

#include <msp430fr5949.h>
#include <stdio.h>
#include <string.h>

#define TXD BIT2
#define RXD BIT1

char string0[255];
char string1[255];
unsigned int i; //Counter
int itterator = 0;
int itteratori = 0;
int strSize = 0;
void sendUART(char channel);
void sendUARTByte(char data, char channel);
void setup();


void main(void)
{
	setup();
	while(1) {
		volatile unsigned int i;            // volatile to prevent optimization

		        UCA0TXBUF = 'A';
		        //UCA1TXBUF = 'A';
		        strcpy(string1, "HELLO WORLD!");
		        strSize = 12;
		        //string = "HELLO WORLD!";
		        //sendUART('b');
		        i = 10000;                          // SW Delay
		        do i--;
		        while(i != 0);
	    }
}

void setup(){
	PM5CTL0 &= ~LOCKLPM5;

	//clock config
	WDTCTL = WDTPW + WDTHOLD; // Stop WDT
	CSCTL0 = CSKEY; //super secret password
	CSCTL1 &= 0x0000; //set DCOCLK to 1 MHz
	CSCTL2 |= 0x0030; //Tie SMCLK to DCOCLK
	CSCTL3 &= 0x0000; //CLK divider set to /1

	__enable_interrupt();

	//UART A0 config
	UCA0CTLW0 |= UCSWRST; //set reset
	UCA0CTLW0 |= 0x0091; // 0000000010010000
	UCA0BRW = 0x0006; //set baudrate of 9600
	UCA0MCTLW = 0x0081; //000000001000

	//Port config
	P2DIR |= 0xFF; // All P2.x outputs
	P2OUT &= 0x00; // All P2.x reset
	P2SEL0 |= 0x00; // P2.0 = RXD, P2.1=TXD
	P2SEL1 |= 0x63; // P2.0 = RXD, P2.1=TXD
	P1DIR |= 0x01; // Set P1.0 to output direction

	UCA0CTLW0 &= 0xFFFE;  //clear reset
	UCA0IE |= UCRXIE; //enable UART A0 interrupts (RX and TX)
	UCA0IE |= UCTXIE;
	UCA0IE |= UCTXCPTIE;


	//UART A1 Config
	UCA1CTLW0 |= UCSWRST; //set reset
	UCA1CTLW0 |= 0x0081; // 0000000010010000
	UCA1BRW = 0x0006; //set baudrate of 9600
	UCA1MCTLW = 0x0081; //000000001000

	//Port config
	P2SEL0 |= 0x00; // P2.5 = TXD, P2.6=RXD
	P2SEL1 |= 0x60; // P2.5 = TXD, P2.6=RXD

	UCA1CTLW0 &= 0xFFFE;  //clear reset
	UCA1IE |= UCRXIE; //enable UART A1 interrupts (RX and TX)
	UCA1IE |= UCTXIE;
	UCA1IE |= UCTXCPTIE;


}



void sendUARTByte(char data, char channel){
	if(channel == 'A'){
		UCA0TXBUF = data;
	}else{
		UCA1TXBUF = data;
	}
}

void sendUART(char channel){
	if(channel == 'A'){
		i = 0;
		UCA0TXBUF = string0[i];
	}else{
		i = 0;
		UCA1TXBUF = string1[i];
	}
}





//interrupt vector
#pragma vector = USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
	//printf("ISR");
	switch(__even_in_range(UCA0IV,18))
	{
		case 0x00: // Vector 0: No interrupts
			break;
		case 0x02: // Vector 2: UCRXIFG
			/*if (UCA0RXBUF == 'a') // 'a' received?
			{
			   i = 0;
			   UCA0IE |= UCTXIE; // Enable USCI_A0 TX interrupt
			  UCA0TXBUF = string[i++];
			}
			*/break;
		case 0x04: // Vector 4: UCTXIFG
			i++;
			if (i != strSize) // TX over?
				UCA0TXBUF = string0[i]; // TX next character
			break;
		default: break;
	}

    P1OUT ^= 0x01;                      // Toggle P1.0 using exclusive-OR
}


//interrupt vector
#pragma vector = USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
	//printf("ISR");
	switch(__even_in_range(UCA0IV,18))
	{
		case 0x00: // Vector 0: No interrupts
			break;
		case 0x02: // Vector 2: UCRXIFG
			/*if (UCA0RXBUF == 'a') // 'a' received?
			{
			   i = 0;
			   UCA0IE |= UCTXIE; // Enable USCI_A0 TX interrupt
			  UCA0TXBUF = string[i++];
			}
			*/break;
		case 0x04: // Vector 4: UCTXIFG
			i++;
			if (i != strSize) // TX over?
				UCA1TXBUF = string1[i]; // TX next character
			break;
		default: break;
	}

    P1OUT ^= 0x01;                      // Toggle P1.0 using exclusive-OR
}


Viewing all articles
Browse latest Browse all 22733

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>