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.

MSP430F Uart and GPIO issue.

Part Number: MSP430F2132

Tool/software: Code Composer Studio

Hi,

Controller             : MSP430F2132

Crystal Oscillator  :16Mhz

Issue                     : GPIO not working while enable UART serial communication.

GPIO was working well before enabling or adding UART code in to project and tested well. Also noted that 16Mhz wave at XOUT pin. After adding uart code in project i noted waves/pulses on UCA0TXD Pin (pin no 15). but havent verified with any terminal software. 

But when i tried GPIO function in same firmaware , GPIO functions are not working as previous.

where did i made mistake? Kindly help to solve.

here follows my code.

#include <msp430.h>

#define _INPUT1 (P2IN & 0x10) //P2.4
#define _INPUT2 (P2IN & 0x20) //P2.5
#define _INPUT3 (P3IN & 0x01) //P3.0
#define _INPUT4 (P3IN & 0x02) //P3.1
#define _INPUT5 (P2IN & 0x01) //P2.0
#define _INPUT6 (P2IN & 0x02) //P2.1
#define _INPUT7 (P2IN & 0x04) //P2.2
#define _INPUT8 (P2IN & 0x08) //P2.3

#define _OUTPUT1_ON P1OUT = P1OUT | 0x01 //P1.0
#define _OUTPUT2_ON P1OUT = P1OUT | 0x02 //P1.1
#define _OUTPUT3_ON P1OUT = P1OUT | 0x04 //P1.2
#define _OUTPUT4_ON P1OUT = P1OUT | 0x08 //P1.3
#define _OUTPUT5_ON P1OUT = P1OUT | 0x10 //P1.4
#define _OUTPUT6_ON P1OUT = P1OUT | 0x20 //P1.5
#define _OUTPUT7_ON P1OUT = P1OUT | 0x40 //P1.6
#define _OUTPUT8_ON P1OUT = P1OUT | 0x80 //P1.6

#define _OUTPUT1_OFF P1OUT = P1OUT & 0xFE //P1.0
#define _OUTPUT2_OFF P1OUT = P1OUT & 0xFD //P1.1
#define _OUTPUT3_OFF P1OUT = P1OUT & 0xFB //P1.2
#define _OUTPUT4_OFF P1OUT = P1OUT & 0xF7 //P1.3
#define _OUTPUT5_OFF P1OUT = P1OUT & 0xEF //P1.4
#define _OUTPUT6_OFF P1OUT = P1OUT & 0xDF //P1.5
#define _OUTPUT7_OFF P1OUT = P1OUT & 0xBF //P1.6
#define _OUTPUT8_OFF P1OUT = P1OUT & 0x7F //P1.6
#define _ALL_OUTPUT_OFF P1OUT = 0x00;

#define _RS485_TX_EN P3OUT = P3OUT | 0x40 //P3.6 = HIGH
#define _RS485_Tx_DIS P3OUT = P3OUT & 0xBF //P3.6 = LOW

#define _RS485_RX_EN P3OUT = P3OUT & 0x7F //P3.7 = LOW
#define _RS485_Rx_DIS P3OUT = P3OUT | 0x80 //P3.7 = HIGH

#define _RS485_TX_TOGGLE P3OUT = P3OUT ^ 0x10 //P3.1 = HIGH

unsigned char buffer[10]={0};
unsigned char i=0;


/**
* main.c
*/

int main(void)
{

WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

BCSCTL1 |= XTS | DIVA_0; /* LFXTCLK 0:Low Freq. / 1: High Freq. */
//ACLK Divider = 0
BCSCTL2 |= DIVS_1 | SELS |DIVM_1|SELM1; //MCLK = LFXT1CLK , divs=1,divm=1,SMCLK=LFXT1CLK
BCSCTL3 |= LFXT1S1; /* Mode 1 for LFXT1 (XTS = 0) */

P1DIR |= 0xFF; // Set P1.0 to output direction
P2SEL = 0xC0;
P2DIR |= 0x00; //set P2 all input
P3SEL |= 0x30; // Use P3.4/P3.5 for USCI_A0
// P3SEL |= 0x00; // Use P3.4/P3.5 for USCI_A0
P3DIR |= 0xDC; //Set P3.0, P3.1 and P3.5 as input

_ALL_OUTPUT_OFF; //reset all outputs

UCA0CTL0 = 0x00; //8,N,1,LSB,Uart, Asynchronous
UCA0CTL1 |= UCSSEL_1; // CLK = ACLK
UCA0BR0 = 65; // 8MHz/9600 = 833
UCA0BR1 = 0x03;
UCA0MCTL = UCBRS2; // Modulation UCBRSx = 3
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE + UCA0TXIE; // Enable USCI_A0 TX/RX interrupt

__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts enabled

//UCA0TXBUF = 'A';
// buffer[5] = 0xAA;
_RS485_TX_EN;
_RS485_RX_EN;
while (1)
{
// UCA0TXBUF = 'A';
// _RS485_TX_TOGGLE;
// _delay_cycles(30000);
//_delay_cycles(100000);

//Blink OUTPUT1
/* _OUTPUT1_ON;
_delay_cycles(80000);
_OUTPUT1_OFF;
_delay_cycles(80000);
*/


if((!(_INPUT1))||(!(_INPUT2))||(!(_INPUT3))||(!(_INPUT4))||(!(_INPUT5))||(!(_INPUT6))||(!(_INPUT7))||(!(_INPUT8))) {
if(!(_INPUT1)) {
_OUTPUT1_ON;
}
if(!(_INPUT2)) {
_OUTPUT2_ON;
}
if(!(_INPUT3)) {
_OUTPUT3_ON;
}
if(!(_INPUT4)) {
_OUTPUT4_ON;
}
if(!(_INPUT5)) {
_OUTPUT5_ON;
}
if(!(_INPUT6)) {
_OUTPUT6_ON;
}
if(!(_INPUT7)) {
_OUTPUT7_ON;
}
if(!(_INPUT8)) {
_OUTPUT8_ON;
}
} else {
_ALL_OUTPUT_OFF;
}
}
//return 0;
}

// USCI A0/B0 Transmit ISR
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCI0TX_ISR (void)
#else
#error Compiler not supported!
#endif
{
UCA0TXBUF = buffer[5]; // Read, justify, and transmit
}

// USCI A0/B0 Receive ISR
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCI0RX_ISR (void)
#else
#error Compiler not supported!
#endif
{
buffer[0] = UCA0RXBUF; // Display RX'ed charater
}

  • > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts enabled
    This will stall forever since there's no wakeup anywhere.

    Reading the rest of your code, my first thought is that you don't want this line at all. If you really want to keep it, add something like this to one (or both) of your ISRs:

    >__bic_SR_register_on_exit(LPM3_bits); // Wake up main()
  • Hi Bruce,

     >__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupts enabled
    This will stall forever since there's no wakeup anywhere.

    You mean this statement put the controller in idle state until there is no wake call on Rx pin. is it?

    Am looking for a interrupt enable when rx receives single char similarly in tx also (when send a char or until clear send buffer ).

    what will the second statement makes effect ? how it will work?

    -nikhil

  • The statement as written will put your program in idle state until there is a wakeup, but there will never be a wakeup. The MSP430 does not automatically wake up the foreground (main) on an interrupt.

    I see now that you aren't enabling interrupts (GIE) anywhere else, so you do probably want to keep "half" of that statement. Try:

     >__bis_SR_register(GIE); // Enable interrupts and keep going

**Attention** This is a public forum