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.

MSP432P401R: MSP432P401R UART Communication with MSP430G2553

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();
}
  • For one thing, you need to make all global variables accessed in the interrupt handlers to be volatile.
  • Okay but although i did all global variables to volatile, the code is still not running. Thank you anyway :)
  •  >       EUSCI_A_UART_MSB_FIRST,                         // MSB First
     
    This looks suspicious -- MSB-first doesn't match the G2553 side, not to mention being generally rather unusual in the UART world.
    Try setting this to LSB-first.
  • Hi Bruce,

    Unfortunately it did not work on me. Do you have any idea for the error that I received?

  • Can,

    Can you provide more details on the error that you see? What MSP432 LaunchPad revision are you using? Black or Red?
  • Hi Evan,

    ı'm using the Red one. Which error are you talking about for code or ccs error?

  • Can,

    The ccs image you posted is not something I would be concerned about. I'm more curious as to what you mean by " some data is coming to RXBUF but whole code is not running." Can you explain what you mean by this? Are you getting some of the data?
  • I'm going to close this thread due to innactivity. If you have another question unrelated to the topic above, please post another thread, if you have any more questions related to this, feel free to post here and thread will reopen.
  • Please accept my apologizes for late respond. The main problem is here that although I'm thinking all the code lines are correct for MSP432, there is no communication between two microprocessor. The MSP430 G2553 is sending data as a transmitter and if receiver is MSP430 G2553 too as a receiver, received data is correctly got but if the receiver is MSP432(The red one), although MSP430 G2553 sending the data, MSP432 cannot get the correct data. I'm doing some mistakes in somewhere on the code but I didnot find. I have to re-explain all the problems that I have beacuse I was very busy when I posted this problem and I couldnot explain correctly to this problem. Thank for your attention again.

  • Can,

    No worries on the late response. Thanks for clarifying that it's a red launchpad. When you say the MSP432 cannot get the correct data, can you give me an example of what data you do receive? Maybe a comparison of what is expected vs what you do so? Or do you see zero communication?

    What is your desired baud rate? Have you made sure that the UART settings youve implemented give each device the expected baud rate you want?

    software-dl.ti.com/.../index.html

    That link above should help with the baud rate settings.
  • Hi Evan,

    First of alli I want to thank you for your attention and fast response. For example, I want to see a value between 0 and 7 on MSP432 receiver but it is getting randomly some values. Although I use that tool for 115200 baudrate, maybe I've made a mistake. I'll try again and write in 24 hour. As a result of this, there is a communication but it is not like that I want.

    Best Regards,

    Nurettin Can ÖZBAKIR
  • Hi Evan,

    I calculated the baud rate settings but they are the same of my settings. So, still it isn't work. Besides when I ran and then stopped the code, I'm getting the error or something which is in below pictures. RXBUF is getting some data but there is not what I want.

  • Can,

    Is there a chance you can provide scope shots using a logic analyzer of the TX and RX pins. This will help see if you are transmitting as expected to the G2553 or if RX is actually causing the issue.

    What are you expecting to receive in the UCARXBUF as opposed to 0x0082?
  • Hi Evan,

    As you can see in the transmitter code, before start the data which is coming from ADC in G2553, three preamble data is being sent by G2553 to correct data package delivery. So, all I want is to see firstly three preamble data and a number between 0 and 7 as a char in MSP432 RXBUF. Unfortunately, I have no chance to publish logic analysis. Nevertheless, let me give you more detail about the code. I want to see a number as char format in MSP432 and in the top - right below picture. In the below picture, received data is directly related to UCARXBUF of msp432. So, the unwanted data is seen there but sometimes 'B' which is preamble 2 can be seen. And also when I paused the running, below 2 tab is opened.

**Attention** This is a public forum