Part Number: MSP432P401R
Other Parts Discussed in Thread: MSP430G2553
Hi everyone,
I'm facing a problem on my project which is my final thesis. In this project, I'm trying to communicate MSP430 with MSP432 by using bluetooth modules on UART. I will share my either transmitter part code and receiver part code but firstly, I want to explain the problem that I am facing for; I'am trying to send some measured data with MSP430 using below code. The MSP430 G2553 is correctly sending the data as a transmitter. If the receiver side is MSP430 G2553 too, the received data from UART is correctly obtained but if the receiver side is MSP432, the data cannot be obtained correctly.
Below code is transmitter part which is running by MSP430G2553;
#include <msp430g2553.h>
char X_Axis;
char Y_Axis;
char Z_Axis;
char Gripper_Axis;
char Preamble_1 = 'A';
char Preamble_2 = 'B';
char Preamble_3 = 'C';
void PIN_Config(void);
void Time_Config(void);
void UART_Config(void);
void ADC_Config(void);
void ADC_Reading_X_Axis(void);
void ADC_Reading_Y_Axis(void);
void ADC_Reading_Z_Axis(void);
void ADC_Reading_Gripper_Axis(void);
void Transmitting_To_MSP432(void);
void main(void)
{
WDTCTL = WDTPW | WDTHOLD;
PIN_Config();
Time_Config();
UART_Config();
ADC_Config();
while(1){
ADC_Reading_X_Axis();
ADC_Reading_Y_Axis();
ADC_Reading_Z_Axis();
ADC_Reading_Gripper_Axis();
Transmitting_To_MSP432();
}
}
void PIN_Config(void){
P1SEL = BIT1 | BIT2;
P1SEL2 = BIT1 | BIT2;
P2DIR = 0xFF;
P2OUT &= ~0x00;
}
void Time_Config(void){
DCOCTL = 0;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
}
void UART_Config(void){
UCA0CTL1 |= UCSWRST | UCSSEL_2;
UCA0BR0 = 8;
UCA0BR1 = 0;
UCA0MCTL = UCBRS_6;
UCA0CTL1 &= ~UCSWRST;
}
void ADC_Config(void){
ADC10CTL0 = SREF_0 | ADC10ON | ADC10SHT_3;
}
void ADC_Reading_X_Axis(void){
ADC10CTL0 &= ~ENC;
ADC10CTL1 = INCH_0 | CONSEQ_0 | ADC10SSEL_0;
ADC10AE0 |= BIT0;
ADC10CTL0 |= ENC | ADC10SC;
while(ADC10CTL1 & ADC10BUSY);
X_Axis = (ADC10MEM >> 7);
}
void ADC_Reading_Y_Axis(void){
ADC10CTL0 &= ~ENC;
ADC10CTL1 = INCH_3 | CONSEQ_0 | ADC10SSEL_0;
ADC10AE0 |= BIT3;
ADC10CTL0 |= ENC | ADC10SC;
while(ADC10CTL1 & ADC10BUSY);
Y_Axis = (ADC10MEM >> 7);
}
void ADC_Reading_Z_Axis(void){
ADC10CTL0 &= ~ENC;
ADC10CTL1 = INCH_4 | CONSEQ_0 | ADC10SSEL_0;
ADC10AE0 |= BIT4;
ADC10CTL0 |= ENC | ADC10SC;
while(ADC10CTL1 & ADC10BUSY);
Z_Axis = (ADC10MEM >> 7);
}
void ADC_Reading_Gripper_Axis(void){
ADC10CTL0 &= ~ENC;
ADC10CTL1 = INCH_5 | CONSEQ_0 | ADC10SSEL_0;
ADC10AE0 |= BIT5;
ADC10CTL0 |= ENC | ADC10SC;
while(ADC10CTL1 & ADC10BUSY);
Gripper_Axis = (ADC10MEM >> 7);
}
void Transmitting_To_MSP432(void){
UCA0TXBUF = Preamble_1;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = Preamble_2;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = Preamble_3;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = X_Axis;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = Y_Axis;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = Z_Axis;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = Gripper_Axis;
while (!(IFG2 & UCA0TXIFG));
}
Below code is receiver part which is running by MSP430G2553 if the MSP430G2553 is chosen as a receiver side;
#include <msp430g2553.h>
int i = 0;
char X_Axis;
char Y_Axis;
char Z_Axis;
char Gripper_Axis;
char Preamble_1 = 0x41;
char Preamble_2 = 0x42;
char Preamble_3 = 0x43;
void PIN_Config(void);
void Time_Config(void);
void UART_Config(void);
void main(void)
{
WDTCTL = WDTPW | WDTHOLD;
PIN_Config();
Time_Config();
UART_Config();
_enable_interrupts();
LPM0;
}
void PIN_Config(void){
P1SEL = BIT1 | BIT2;
P1SEL2 = BIT1 | BIT2;
P1DIR = 0xF9;
P2DIR = 0xFF;
P1OUT = 0x00;
P2OUT = 0x00;
}
void Time_Config(void){
DCOCTL = 0;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
}
void UART_Config(void){
UCA0CTL1 |= UCSWRST | UCSSEL_2;
UCA0BR0 = 8;
UCA0BR1 = 0;
UCA0MCTL = UCBRS_6;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE;
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCIAB0RX_ISR (void){
if(i == 0){
if(UCA0RXBUF == Preamble_1)
i = 1;
else
i = 0;
}
else if(i == 1){
if(UCA0RXBUF == Preamble_2)
i = 2;
else
i = 0;
}
else if(i == 2){
if(UCA0RXBUF == Preamble_3)
i = 3;
else
i = 0;
}
else if(i == 3){
X_Axis = UCA0RXBUF;
i = 4;
}
else if(i == 4){
Y_Axis = UCA0RXBUF;
i = 5;
}
else if(i == 5){
Z_Axis = UCA0RXBUF;
i = 6;
}
else if(i == 6){
Gripper_Axis = UCA0RXBUF;
i = 0;
}
}
And belowcode is receiver part which is running by MSP432, if the MSP432 is chosen as a receiver side;
#include "driverlib.h"
#include <stdint.h>
#include <stdbool.h>
int i = 0;
char X_Axis;
char Y_Axis;
char Z_Axis;
char Gripper_Axis;
char Preamble_1 = 'A';
char Preamble_2 = 'B';
char Preamble_3 = 'C';
char Received_Data = 0x00;
const eUSCI_UART_Config uartConfig =
{
EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
1, // BRDIV = 8
10, // UCxBRF = -
0, // UCxBRS = 0xD6
EUSCI_A_UART_NO_PARITY, // No Parity
EUSCI_A_UART_MSB_FIRST, // MSB First
EUSCI_A_UART_ONE_STOP_BIT, // One Stop Bit
EUSCI_A_UART_MODE, // UART Mode
EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION, // No-Oversampling
};
int main(void)
{
WDT_A_holdTimer();
/* Selecting P1.2 and P1.3 in UART mode */
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);
CS_setDCOFrequency(1000000);
UART_initModule(EUSCI_A2_BASE, &uartConfig); /* Configuring UART Module */
UART_enableModule(EUSCI_A2_BASE); /* Enable UART module */
UART_enableInterrupt(EUSCI_A2_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT); /* Enabling interrupts */
Interrupt_enableInterrupt(INT_EUSCIA2);
Interrupt_enableMaster();
Interrupt_enableSleepOnIsrExit();
while(1)
{
PCM_gotoLPM0();
}
}
void EUSCIA2_IRQHandler(void)
{
uint32_t status = UART_getEnabledInterruptStatus(EUSCI_A2_BASE);
UART_clearInterruptFlag(EUSCI_A2_BASE, status);
if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
{
Received_Data = UART_receiveData(EUSCI_A2_BASE);
if(i == 0){
if(Received_Data == Preamble_1)
i = 1;
else
i = 0;
}
else if(i == 1){
if(Received_Data == Preamble_2)
i = 2;
else
i = 0;
}
else if(i == 2){
if(Received_Data == Preamble_3)
i = 3;
else
i = 0;
}
else if(i == 3){
X_Axis = Received_Data;
i = 4;
}
else if(i == 4){
Y_Axis = Received_Data;
i = 5;
}
else if(i == 5){
Z_Axis = Received_Data;
i = 6;
}
else if(i == 6){
Gripper_Axis = Received_Data;
i = 0;
}
}
Interrupt_disableSleepOnIsrExit();
}


