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.

CAN'T SEND THE UART COMMANDS(DATA) FROM BOOSTERPACK TO MSP430 LAUNCHPAD WITH MSP430G2452

Other Parts Discussed in Thread: MSP430G2452

  Hello,

I am trying to get the output of led driver program..the program is as follows:

// LEDdriver.c

//

// LEDdriver.c is to be used on a msp430 launchpad device that is connected to another msp430 launchpad device that is connect to the Capacitive Touch BoosterPack

//

// Setup:

// The first msp430 is loaded with this code

// The second msp430 is loaded with the Capacitive Touch BoosterPack demo code

// P1.2(RX) connects to P1.1(TX) (the UART transmitter) on the msp430 that is connected to the Capacitive Touch BoosterPack

// P1.0 (BIT0) connects to the center LED

// P1.4 (BIT4) connects to the 30 degree LED

// P1.3 (BIT3) connects to the 60 degree LED

// P1.7 (BIT7) connects to the 120 degree LED

// P1.6 (BIT6) connects to the 150 degree LED

// P2.2 (BIT2) connects to the 210 degree LED

// P2.1 (BIT1) connects to the 240 degree LED

// P2.0 (BIT0) connects to the 300 degree LED

// P1.5 (BIT5) connects to the 330 degree LED

// pin 20 (GND) connects to ground

// All LEDs have a 200 ohm resistor in series before gnd.

/*----------------- LED definition---------------------------------------------

P1 BIT7 P1 BIT3

P1 BIT6 P1 BIT4

P1 BIT0

P2 BIT2 P1 BIT5

P2 BIT1 P2 BIT0

*----------------------------------------------------------------------------*/

//

// Device Pin Requirement:

// This code uses a 20 pin msp430.

// If the msp430 has 14 pins, change LED connections to:

// P2.0 (BIT0) to P2.6 (BIT6) (XIN)

// P2.1 (BIT1) to P2.7 (BIT7) (XOUT)

// P2.2 (BIT2) to P1.1 (BIT1) (TXD)

// and modify:

// P1LEDs

// P2LEDs

// startSequenceP1

// startSequenceP2

// LedStartUpSequence

// TimerA_UART_init

//

// LEDdriver.c does:

// receives UART commands from the Capacitive Touch BoosterPack demo code

// When a pin is set high, a ~3.2V is set on the output, which turns on the LED.

// when it receives

// wake-up command: it does the same led blink sequence as the Capacitive Touch BoosterPack

// sleep command: it turns on the center led

// middle button command: it turns the center led on then off the next time

// any other command: the outside lights blink off then on then off

//

// Sources:

// uses uart.h and uart.c from the firmware for CapTouch_BoosterPack_UserExperience

// uart.h was changed: the device include file was to changed to match the header file in this file

// uart.c was changed: TACCTL1 = SCS + CM1 + CAP + CCIE; was uncommented

// uses functions and code from Cap Touch Demo code

// uses Timer_A UART - Receive Interrupt Handler from MSP430G2xx1 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, 32kHz ACLK

#include

<msp430G2452.h>

#include "uart.h"

#define

GREEN_LED BIT6

// for debug

#define

RED_LED BIT0

// for debug

//------------------------------------------------------------------------------

// Labels for the UART Commands

//------------------------------------------------------------------------------

#define

WAKE_UP_UART_CODE 0xBE

#define

WAKE_UP_UART_CODE2 0xEF

#define

SLEEP_MODE_UART_CODE 0xDE

#define

SLEEP_MODE_UART_CODE2 0xAD

#define

MIDDLE_BUTTON_CODE 0x80

#define

INVALID_GESTURE 0xFD

#define

GESTURE_START 0xFC

#define

GESTURE_STOP 0xFB

#define

COUNTER_CLOCKWISE 1

#define

CLOCKWISE 2

//#define GESTURE_POSITION_OFFSET 0x20

#define

WHEEL_POSITION_OFFSET 0x30

//#define RIGHT 0x40

//#define LEFT 0x08

//#define UP 0x10

//#define DOWN 0x80

#define

DELAY (100000)

// delay for the start-up sequence

//------------------------------------------------------------------------------

// Labels for LEDs pins

//------------------------------------------------------------------------------

/*----------------- LED definition---------------------------------------------

P1 BIT7 P1 BIT3

P1 BIT6 P1 BIT4

P1 BIT0

P2 BIT2 P1 BIT5

P2 BIT1 P2 BIT0

*----------------------------------------------------------------------------*/

#define

P1LEDs (BIT3 + BIT4 + BIT5 + BIT6+ BIT7)

#define

P2LEDs (BIT0 + BIT1 + BIT2)

#define

CenterLED BIT0

const

unsigned charstartSequenceP1[6] =

{BIT1,

BIT3,

BIT4,

BIT5,

BIT6,

BIT7

};

const

unsigned charstartSequenceP2[3] =

{

BIT0,

BIT1,

BIT2

};

//------------------------------------------------------------------------------

// Global variables used for full-duplex UART communication

//------------------------------------------------------------------------------

unsigned

char rxBuffer;

// Received UART character

unsigned

char rxBufferLast;

// Previous Received UART character

//------------------------------------------------------------------------------

// Functions for turning LEDs on and off

//------------------------------------------------------------------------------

void

LedStartUpSequence(void);

void

CenterLEDOnOnly(void);

void

LEDsOff(void);

void

OutsideLEDsOff(void);

void

OutsideLEDsOn(void);

//------------------------------------------------------------------------------

// Setup Functions

//------------------------------------------------------------------------------

void

SetupPins(void);

void

InitializeClocks(void);

int

CenterOn=0;

//------------------------------------------------------------------------------

// main()

//------------------------------------------------------------------------------

void

main(void)

{

WDTCTL = WDTPW + WDTHOLD;

// Stop watchdog timer

InitializeClocks();

SetupPins();

__enable_interrupt();

TimerA_UART_init();

// Start Timer_A UART

for (;;)

{

// Wait for incoming character

__bis_SR_register(LPM0_bits+GIE);

switch (rxBuffer)

{

case WAKE_UP_UART_CODE:// needs to recieve second command to be complete

break;

case WAKE_UP_UART_CODE2:

if (rxBufferLast==WAKE_UP_UART_CODE)

LedStartUpSequence();

break;

case SLEEP_MODE_UART_CODE:// needs to receive second command to be complete

break;

case SLEEP_MODE_UART_CODE2:

if (rxBufferLast==SLEEP_MODE_UART_CODE)

CenterLEDOnOnly();

break;

case MIDDLE_BUTTON_CODE:

P1OUT |=0X01;

__delay_cycles(10000);

if (rxBufferLast==MIDDLE_BUTTON_CODE)// needs to receive second command to be complete

if(CenterOn==0) // if not on, then turn center led on

{

P1OUT |= CenterLED;

CenterOn=1;

}

else

{

P1OUT &= ~CenterLED;

CenterOn=0;

}

break;

case GESTURE_STOP:

if (rxBufferLast==GESTURE_STOP)// needs to receive second command to be complete

LEDsOff();

break;

case GESTURE_START:

break;

default: // data from LaunchPad is not code, but value

P1OUT |=0x40;

OutsideLEDsOff();

__delay_cycles(DELAY);

OutsideLEDsOn();

__delay_cycles(DELAY);

OutsideLEDsOff();

__delay_cycles(DELAY);

break;

}

}

}

void

TimerA_UART_init(void)

{

TACCTL0 = OUT;

// Set TXD Idle as Mark = '1'

TACCTL1 = SCS + CM1 + CAP + CCIE;

// Sync, Neg Edge, Capture, Int

TACTL = TASSEL_2 + MC_2;

// SMCLK, start in continuous mode

}

 

//------------------------------------------------------------------------------

// SetupPins - Sets up the port pins used

//------------------------------------------------------------------------------

void

SetupPins(void)

{

P1DIR = 0xFF & ~UART_RXD;

// Set all port 1 pins but RXD to output

P1OUT = 0x00;

// Initialize all GPIO to off

P2DIR = 0xFF;

// Set all port 2 pins to output

P2OUT = 0x00;

// Initialize all GPIO to off

}

//------------------------------------------------------------------------------

// InitializeClocks - Sets clock to 1MHz

//------------------------------------------------------------------------------

void

InitializeClocks(void)

{

BCSCTL1 = CALBC1_1MHZ;

// Set range

DCOCTL = CALDCO_1MHZ;

BCSCTL2 &= ~(DIVS_3);

// SMCLK = DCO / 8 = 1MHz

}

// ----------------LedStartUpSequence-------------------------------------------

// Display an LED lighting sequence to indicate the wake up event

//------------------------------------------------------------------------------

void

LedStartUpSequence(void)

//takes 16*DELAY

{

unsigned char i;

// clockwise sequence

for(i=0; i<3; i++)

{

P1OUT = startSequenceP1[i];

__delay_cycles(DELAY);

}

P1OUT = 0;

for(i=0; i<3; i++)

{

P2OUT = startSequenceP2[i];

__delay_cycles(DELAY);

}

P2OUT = 0;

for(i=3; i<5; i++)

{

P1OUT = startSequenceP1[i];

__delay_cycles(DELAY);

}

// counter-clockwise sequence

for(i=4; i>2; i--)

{

P1OUT = startSequenceP1[i];

__delay_cycles(DELAY);

}

P1OUT = 0;

for(i=3; i>0; i--)

{

P2OUT = startSequenceP2[i-1];

__delay_cycles(DELAY);

}

P2OUT = 0;

for(i=3; i>0; i--)

{

P1OUT = startSequenceP1[i-1];

__delay_cycles(DELAY);

}

P1OUT = 0;

// Turn off all LEDs

CenterOn=0;

}

//------------------------------------------------------------------------------

// CenterLEDOnOnly - Turns on center LED and turns off all other LEDs

//------------------------------------------------------------------------------

void

CenterLEDOnOnly(void)

{

P1OUT = CenterLED;

// Turn on center LED

P2OUT = 0;

// Turn off all other LEDs

CenterOn=1;

}

//------------------------------------------------------------------------------

// LEDsOff - Turn off all LEDs

//------------------------------------------------------------------------------

void

LEDsOff(void)

{

P1OUT &= ~P1LEDs;

P1OUT &= ~CenterLED;

P2OUT &= ~P2LEDs;

CenterOn=0;

}

//------------------------------------------------------------------------------

// OutsideLEDsOff - Turn off Outside LEDs

//------------------------------------------------------------------------------

void

OutsideLEDsOff(void)

{

P1OUT &= ~P1LEDs;

P2OUT &= ~P2LEDs;

}

//------------------------------------------------------------------------------

// OutsideLEDsOn - Turn on outside LEDs

//------------------------------------------------------------------------------

void

OutsideLEDsOn(void)

{

P1OUT |= P1LEDs;

P2OUT |= P2LEDs;

}

//------------------------------------------------------------------------------

// Timer_A UART - Receive Interrupt Handler

//------------------------------------------------------------------------------

//#pragma vector = TIMERA1_VECTOR

#pragma

vector = TIMER0_A1_VECTOR

__interrupt

void Timer_A1_ISR(void)

{

static unsigned char rxBitCnt = 8;

static unsigned char rxData = 0;

switch (__even_in_range(TAIV, TAIV_TAIFG)) { // Use calculated branching

case TAIV_TACCR1: // TACCR1 CCIFG - UART RX

TACCR1 += UART_TBIT;

// Add Offset to CCRx

if (TACCTL1 & CAP) { // Capture mode = start bit edge

TACCTL1 &= ~CAP;

// Switch capture to compare mode

TACCR1 += UART_TBIT_DIV_2;

// Point CCRx to middle of D0

}

else {

rxData >>= 1;

if (TACCTL1 & SCCI) { // Get bit waiting in receive latch

rxData |= 0x80;

}

rxBitCnt--;

if (rxBitCnt == 0) { // All bits RXed?

rxBufferLast = rxData;

rxBuffer = rxData;

// Store in global variable

rxBitCnt = 8;

// Re-load bit counter

TACCTL1 |= CAP;

// Switch compare to capture mode

__bic_SR_register_on_exit(LPM0_bits);

// Clear LPM0 bits from 0(SR)

}

}

break;

}

}

//------------------------------------------------------------------------------

**Attention** This is a public forum