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.

Configuring the MSP430 USCI_A1 UART module

Other Parts Discussed in Thread: MSP430F5529

Hi guys,


I have been developing a UART library for the msp430f5529 which I am testing on my msp430f5529 launchpad.


I have written the code for the USCI_A0 module and it works perfectly. Now I transferred it to the USCI_A1 module.

Basically the code (initialisation and algorithm) is exactly the same but I changed the pinouts, ISR nector name and register names from, for example, UCA0IFG to UCA1IFG (just the number).


When I run the algorithm, the process does go into the ISR, runs properly through all the processes, yet no data can be detected on the pins.

Regarding the launchpad dev board, I connected my logic analyser with the male header's pins TXD and RXD pins next to the SBW RST and SBW TST pins; i checked with the schematic of the board that these are connected with the  pins 4.4 and 4.5 on the msp respectively.

The following is the code I am using:

//This function sets the UART ports and registers
int UART_initialise(char *UART_module){

		P4SEL 	|= RXD_UCA1 + TXD_UCA1 ; // P4.5 = RXD, P4.4=TXD
		P4DIR   |= TXD_UCA1; // set as output
		P4DIR   &= ~RXD_UCA1; // set as input

		UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**

		//Set UART module
		UCA1CTL0 = UCMODE_0; //set UART mode
		UCA1CTL1 |= UCSSEL_1; // Set ACLK(XT1, 32KHz) as BRCLK
		UCA1BR0 = 0x03;                           // 32kHz/9600=3.41 (see User's Guide)
		UCA1BR1 = 0x00;                           //
		UCA1MCTL = UCBRS_3+UCBRF_0;               // Modulation UCBRSx=3, UCBRFx=0

		UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

		return 1;

}


//This function transmits string (char array) pointed to by data_to_send
//via UART.
//Transfer is ready when transfer_ready variable is asserted.
int UART_transmit(char *data_to_send,char *UART_module)
{
		UART_transmit_function_UCA1 = 1;

		UCA1IFG &= ~UCTXIFG; //clear flag (just in case)

		UART_transmit_function_ready_UCA1 = 0; //global variable; 1 is transmit is ready
		tx_data_cnt_UCA1 = 0;	//global variable; reset counter
		tx_data_UCA1 = data_to_send; // copy pointer to global varible
		tx_data_size_UCA1 = strlen(tx_data_UCA1); //global variable, calculate size of string to send

		UCA1TXBUF = *(tx_data_UCA1 + tx_data_cnt_UCA1*sizeof(char)); //load UART transmit buffer

		UCA1IE |= UCTXIE;  //Enable TX interrupt

		return 1;
}


ISR:

#pragma vector = USCI_A1_VECTOR
__interrupt void USCIA1RTX_ISR(void){

extern	int UART_transmit_function_UCA1;
extern	int UART_transmit_function_ready_UCA1;
extern	int tx_data_cnt_UCA1;
extern	char *tx_data_UCA1;
extern	int tx_data_size_UCA1;


	if((UCA1IFG & UCTXIFG) != 0){

		   ++tx_data_cnt_UCA1;

		   if(tx_data_cnt_UCA1 <= (tx_data_size_UCA1-1)){
			   UCA1TXBUF = *(tx_data_UCA1 + tx_data_cnt_UCA1*sizeof(char)); //load UART transmit buffer
		   }
		   else {
			   UART_transmit_function_ready_UCA1 = 1;
			   UCA1IE &= ~UCTXIE; // Disable USCI_A0 TX interrupt
			   UCA1IFG &= ~UCTXIFG; //clear flag
			   //__bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
		   }
	
   }
}

I am using the XTl1 oscillator(32Khz)..


Thanks for any help, any suggestion is appreciated.

Thanks for your time.

best regards,

Eman

  • USCI A1 is used as the backchannel UART on that launchpad board.  Do you need to remove the jumpers?

  • Yes you do. I did remove the jumpers.

    thanks for your reply
  • My only other thought is that Port 4 on that flavor of MSP430 is part of the port mapping module. In the past, I've had to unlock the port mapping module, force my pin mappings, and then relock the module, regardless of what its defaults are set for. Good luck!
  • Hi James,

    Well maybe I should give it a try. 

    The thing is that, I did manage to get the code running once for USCI_A1 (it got corrupted somehow, shortly after), and this was without doing any changes with the PM... I would try anyway.

    Any other suggestions are greatly welcome.

    Thnaks,

    regards

  • The USCI automatically sets the port pin direction, so no need to set/clear P4DIR.

    You pass *UART_module to your functions but never use it. I guess it is meant for modularizing the use of different USCI modules, but it is simply extending and slowing the code right now.

    in UART_transmit you load TXBUF with an overly complex expression. You know that you're sending the first byte here to 'jump start' the transmission. So simply load the data count with 1 (the ISR shall send the second byte, not the first one again) and load TXBUF with *tx_data.
    Using sizeof(char) is misleading here: if a char would be 16 bit, then the whole code would fail anyway, as TXBUF only takes bytes. The transmission would skip every second byte then rather than simply sending all bytes. You should adjust the size instead to the number of bytes in the string rather than the number of elements.

    All your variables that are used in main as well as inside the ISR should be declared volatile. Especially UART_transmit_function_ready_UCA1. Else main perhaps won't ever notice that it is set by the ISR, if code optimization is used.

    Regarding the missing signal output:
    Are you sure that RXD_UCA1 and TXD_UCA1 are correct (BIT4 and BIT5)?
    Do you use any library that could access the port mapping? Or any other code that configures P4SEL (undoing your selection)?
    And please don't use '+' to combine bit values. While if done properly, the result is the same as with the binary Or operator '|', in case of a mistake you'll do something completely unintended and won't notice.

    James: missing default port mapping may occur on experimental silicon (XMS430), which is often delivered as free samples (as long as still in stock). On regular units, this shouldn't happen, or else it is listed in the errata sheet.
  • Hi Jens-Micheal,

    Thanks for your reply. 

    I appreciate your suggestions. I will revise my firmware accordingly.

    I have since "solved" the problem, the UART pins on my board where burned up..

    Thanks again

**Attention** This is a public forum