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.

MSP430g2553 uart to bluetooth

Other Parts Discussed in Thread: MSP430G2553

Hello, I'm new in this kind of programming, i'm trying to use the UART so I can communicate the MSP with an HC 06 bluetooth module, so, i send a signal from a device to the HC06 and then it sends it to the MSP, it sounds kinda simple, the thing is, with that signal, I'm trying to send two PWM's to a brushless motor and a servo.

I know the data is transmitted, but i don't know if the HC06 sends the same data to the MSP or if i have to change it somehow, and because of that, the servo and the brushless doesn't move at all. 

Here is my code so far:

#include "msp430g2553.h"

#define MCU_CLOCK 1100000
#define PWM_FREQUENCY 46

#define SERVO_STEPS 179 // Maximum amount of steps in degrees (180 is common)
#define SERVO_MIN 700 // The minimum duty cycle for this servo
#define SERVO_MAX 2800// The maximum duty cycle

unsigned int PWM_Period = (MCU_CLOCK / PWM_FREQUENCY); // PWM Period
unsigned int PWM_Duty = 0; // %

void main (void){
unsigned int servo_stepval, servo_stepnow;
unsigned int servo_lut[ SERVO_STEPS+1 ];
unsigned int i;
// Calculate the step value and define the current step, defaults to minimum.
servo_stepval = ( (SERVO_MAX - SERVO_MIN) / SERVO_STEPS );
servo_stepnow = SERVO_MIN;

// Fill up the LUT
for (i = 0; i < SERVO_STEPS; i++) {
servo_stepnow += servo_stepval;
servo_lut[i] = servo_stepnow;
}

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

DCOCTL = 0; /* Use Calibration values for 1MHz Clock DCO*/
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 | BIT2 ; /* Configure Pin Muxing P1.1 RXD and P1.2 TXD */
P1SEL2 = BIT1 | BIT2;
UCA0CTL1 = UCSWRST; /* Place UCA0 in Reset to be configured */
UCA0CTL1 |= UCSYNC; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1

// Setup the PWM
TA0CCTL1 = OUTMOD_7; // TA0CCR1 reset/set
TA0CTL = TASSEL_2 + MC_1; // SMCLK, upmode
TA0CCR0 = PWM_Period-1; // PWM Period
TA0CCR1 = PWM_Duty; // TA0CCR1 PWM Duty Cycle
P1DIR |= BIT5; // P1.5 = output
P1SEL |= BIT5;
TA1CCTL1 =OUTMOD_7;
TA1CTL = TASSEL_2 + MC_1;
TA1CCR0 = PWM_Period -1; // PWM brushless
TA1CCR1 = PWM_Duty; //
P2DIR |= BIT0; //P2.0 output
P2SEL |= BIT0; //

/* Take UCA0 out of reset */
UCA0CTL1 &= ~UCSWRST;
/* Enable USCI_A0 RX interrupt */
IE2 |= UCA0RXIE;

        __bis_SR_register(GIE);       //  interrupts enabled

while (1){

// Go to 0°
if (UCA0RXBUF==0x04){
TA0CCR1 = servo_lut[0];
TA1CCR1 = PWM_Period/0x0A;
}

// Go to 45°
if (UCA0RXBUF==0x01){
TA0CCR1 = servo_lut[45];
TA1CCR1 = PWM_Period/0x02;
}

// Go to 90°
if(UCA0RXBUF==0x02){
TA0CCR1 = servo_lut[90];
TA1CCR1 = PWM_Period;
}
//Go to 135°
if(UCA0RXBUF==0x03){
TA0CCR1 = servo_lut[135];
TA1CCR1 = PWM_Period/0x02;
}
// Go to 180°
if (UCA0RXBUF==0x06){
TA0CCR1 = servo_lut[175];
TA1CCR1 = PWM_Period/0x0A;
}
//STOP
if (UCA0RXBUF==0x05){
TA0CCR1 = servo_lut[90];
TA1CCR1 =0;
}

}
}

Best regards and thanks for your help.

Alejandro.

**Attention** This is a public forum