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.

CCS/MSP-EXP430FR4133: About UART transmit signal while the lights turns round

Part Number: MSP-EXP430FR4133

Tool/software: Code Composer Studio

Hi!

First of all, I have to admit that I am absolutely new to both C language and microcontroller.

I have asked a question before about communication through UART and I have been directed to CCS.

However, when I try to simply combine two different code together, there are some problems.

I have been taught before and got a code about turning lights blinking as a circle(It really works!) But when I add UART_01 code to it, the MSP430 can only communicate with PC but the light part doesn't work. Why did that happen?

Here is my code for it.   I use IAR for my work. Waiting for reply

------------------------------------------------

#include <msp430.h>
#include <driverlib.h>
#include "LedDriver.h"

void Init_GPIO();


int main(void)
{
//Default MCLK = 1MHz

unsigned int i = 0;
unsigned char dialValue = 0x01; //ask the first light to turn on
unsigned int pinState;
unsigned int lastState=1;
unsigned int dialGoingCW=1;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

initialiseLedDial();
//Switch 1 //configure a pin as an input
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3);



// Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
PMM_unlockLPM5();



// Configure GPIO
Init_GPIO();
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate 1previously configured port settings

__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first
CSCTL1 |= DCORSEL_3; // Set DCO = 8MHz
CSCTL2 = FLLD_0 + 243; // DCODIV = 8MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // Poll until FLL is locked

CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
// default DCODIV as MCLK and SMCLK source

// Configure UART pins
P1SEL0 |= BIT0 | BIT1; // set 2-UART pin as second function

// Configure UART
UCA0CTLW0 |= UCSWRST;
UCA0CTLW0 |= UCSSEL__SMCLK;

// Baud Rate calculation
// 8000000/(16*9600) = 52.083
// Fractional portion = 0.083
// User's Guide Table 14-4: UCBRSx = 0x49
// UCBRFx = int ( (52.083-52)*16) = 1
UCA0BR0 = 52; // 8000000/16/9600
UCA0BR1 = 0x00;
UCA0MCTLW = 0x4900 | UCOS16 | UCBRF_1;

UCA0CTLW0 &= ~UCSWRST; // Initialize eUSCI
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM3_bits|GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger






while(1) //every step on mean function will recall this part to test button state
{
//test button state
pinState = GPIO_getInputPinValue(GPIO_PORT_P1, GPIO_PIN3);

if(lastState==1)//botton not being pressed
{
if(pinState==0)
{
dialGoingCW=!dialGoingCW;
__delay_cycles(10000);//Dealy 10 ms;
}
}
lastState=pinState;

//updated value
if(1==dialGoingCW)
{
dialValue = dialValue * 0x02;
if(0x00 == dialValue)
dialValue = 0x01;
}
else
{
dialValue = dialValue / 0x02;
if(0x00 == dialValue)
dialValue = 0x80;
}

//Set value
setLedDial(dialValue);

//Refresh display (10 times for each position)
for(i = 0; i < 10; i++)
refreshLedDial();

}
}


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
while(!(UCA0IFG&UCTXIFG));
UCA0TXBUF = UCA0RXBUF;
__no_operation();
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
default: break;
}
}


void Init_GPIO()
{
P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF;
P5DIR = 0xFF; P6DIR = 0xFF; P7DIR = 0xFF; P8DIR = 0xFF;
P1REN = 0xFF; P2REN = 0xFF; P3REN = 0xFF; P4REN = 0xFF;
P5REN = 0xFF; P6REN = 0xFF; P7REN = 0xFF; P8REN = 0xFF;
P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00;
P5OUT = 0x00; P6OUT = 0x00; P7OUT = 0x00; P8OUT = 0x00;
}

  • Hi Mengxue,

    I will assign our team member to check your problem and reply you later.
  • Hi Mengxue,
    Can you post the code for initialiseLedDial();, setLedDial(dialValue);, and refreshLedDial(); ? We might be able to get a better idea of what is happening with this code.
    BR,
    Leo
  • Hi, Leo

    Here are what I think you are asking for. 

    --------------------------

    void initialiseLedDial()
    {
    //GPIO 2.7
    GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN7);

    //GPIO 5.1, 5.2, 5.3
    //Inserted by student

    GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3);


    //GPIO 8.0
    //Inserted by student
    GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_PIN0);

    }

    -------------------------------------------------

    /**
    Refresh the display
    */
    void refreshLedDial()
    {
    //Refresh lower bank (LEDs 1-4)
    //Inserted by student
    GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN7);

    if(ledValue_ & 0x01)
    GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);
    else
    GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);

    if(ledValue_ & 0x02)
    GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1);
    else
    GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1);

    if(ledValue_ & 0x04)
    GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2);
    else
    GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2);

    if(ledValue_ & 0x08)
    GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3);
    else
    GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3);



    __delay_cycles(10000); //Delay 10ms
    //Refresh lower bank (LEDs 5-9)
    //Inserted by student

    GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN7);

    if(ledValue_ & 0x80)
    GPIO_setOutputLowOnPin(GPIO_PORT_P8, GPIO_PIN0);
    else
    GPIO_setOutputHighOnPin(GPIO_PORT_P8, GPIO_PIN0);

    if(ledValue_ & 0x40)
    GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN1);
    else
    GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN1);

    if(ledValue_ & 0x20)
    GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN2);
    else
    GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN2);

    if(ledValue_ & 0x10)
    GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3);
    else
    GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3);




    __delay_cycles(10000); //Delay 10ms
    }

    ---------------------------------------------------------------------------------

    void setLedDial(unsigned char value)
    {
    ledValue_ = value;
    }

    ---------------------------------------------------------------------------------

    Waiting for your reply.

    Thanks!

    Mengxue

  • Hi Mengxue,

    When you enable the UART, you are mapping two pins to some specific pins on the device:

    // Configure UART pins
    P1SEL0 |= BIT0 | BIT1; // set 2-UART pin as second function

    You should check in the user's guide to see which two pins are being mapped in this case. (You can also looks at the schematic to see where these UART pins are connected when you are communicating with the device.) It's possible that your LED GPIO code is in conflict with the mapped function you have for these pins.

    BR,
    Leo

**Attention** This is a public forum