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/MSP432P401R: Urgent fix needed. Serial Port communication issue. Trying to implement UART serial communication !!!

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi I am trying to send a character through the serial communication port using the code given below. The code is used to control the speed of a stepper motor connected to Msp432P401R. I am trying to send a character "B" over to putty on pressing  button P1.1 .Upon button press the direction of the motor changes and it is indicated by the character "B". At present I am able to transmit the data but it is being received in putty as some null value or some other character. I have checked the baud rate , parity bits and stop bits. It all seems to be correct. 


#include "msp432.h"
volatile unsigned int i;
//char TXData = '1';
int main(void) {

WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // Stop WDT


// GPIO Setup
P4->OUT &= ~BIT6; //Direction of Motor
P4->DIR |= BIT6; //Set Direction of the motor

P1->OUT = BIT1;
P1->REN = BIT1; // Enable pull-up resistor (P1.1 output high)
P1->IFG = 0; // Clear all P1 interrupt flags
P1->IE = BIT1; // Enable interrupt for P1.1
P1->IES = BIT1; // Interrupt on high-to-low transition


P2->SEL0 |= 0x80;
P2->SEL1 &= ~0x80;//PWM
P2->DIR |= 0x80;

TIMER_A0->CCR[0] = 10000 - 1; /* PWM Period */
TIMER_A0->CCTL[4] = 0xE0; /* CCR4 reset/set mode */
TIMER_A0->CTL = 0x0214; /* use SMCLK, count up, clear TA0R register */

P5->SEL1 |= BIT4; // Configure P5.4 for ADC
P5->SEL0 |= BIT4;


//Ports for UART and LED

P1->DIR |= BIT0;
P1->OUT &= ~BIT0; // P1.0 LED

// Configure UART pins
P1->SEL0 |= BIT2 | BIT3; // set 2-UART pin as second function
//UART config
EUSCI_A0->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset
EUSCI_A0->CTLW0 = EUSCI_A_CTLW0_SWRST |EUSCI_B_CTLW0_SSEL__SMCLK; // Remain eUSCI in reset and Configure eUSCI clock source for SMCLK

// EUSCI_A0->BRW = 1; // Using baud rate calculator
// EUSCI_A0->MCTLW = (10 << EUSCI_A_MCTLW_BRF_OFS) |EUSCI_A_MCTLW_OS16;
// EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST;// Initialize eUSCI
// EUSCI_A0->IE |= EUSCI_A_IE_RXIE; // Enable USCI_A0 RX interrupt
EUSCI_A0->BRW = 78; // 12000000/16/9600
EUSCI_A0->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) |EUSCI_A_MCTLW_OS16;
EUSCI_A0->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI
EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG; // Clear eUSCI RX interrupt flag
EUSCI_A0->IE |= EUSCI_A_IE_RXIE; // Enable USCI_A0 RX interrupt


// Enable global interrupt
__enable_irq(); // Enable ADC interrupt in NVIC module
NVIC->ISER[0] = 1 << ((ADC14_IRQn) & 31);

// Sampling time, S&H=16, ADC14 on
ADC14->CTL0 = ADC14_CTL0_SHT0_2 | ADC14_CTL0_SHP | ADC14_CTL0_ON;//,Pulse sample mode is selected,core is ready to power up when a valid conversion is triggered.
ADC14->CTL1 = ADC14_CTL1_RES_2; // Use sampling timer, 12-bit conversion results

ADC14->MCTL[0] |= ADC14_MCTLN_INCH_1; // A1 ADC input select; Vref=AVCC
ADC14->IER0 |= ADC14_IER0_IE0; // Enable ADC conv complete interrupt

ADC14->IER0 = ADC14_IER0_IE0; // Enable ADC14IFG.0
SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; // Wake up on exit from ISR

// Ensures SLEEPONEXIT takes effect immediately
__DSB();

while (1)
{

//P1->OUT &= ~BIT0;
//printf("%d",TXData);
// for (i = 200; i > 0; i--); // Delay

//Start sampling/conversion
ADC14->CTL0 |= ADC14_CTL0_ENC | ADC14_CTL0_SC;
__sleep();

__no_operation(); // For debugger
}
}

// ADC14 interrupt service routine
void ADC14_IRQHandler(void) {
volatile uint8_t temp;
if (ADC14->MEM[0] > 0x0F & ADC14->MEM[0] <= 0x7F) {
P4->OUT = 0x0000;
TIMER_A0->CCR[0] = 0;
TIMER_A0->CCR[4] = 0;

}

if (ADC14->MEM[0] > 0x7F & ADC14->MEM[0] <= 0xFF) {
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;

TIMER_A0->CCR[0] = 50000 - 1;
TIMER_A0->CCR[4] = 50000 / 5;

}
else if (ADC14->MEM[0] > 0xFF & ADC14->MEM[0] <= 0x2FF) {
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;

}
P1->IFG &= ~BIT1;


TIMER_A0->CCR[0] = 40000 - 1;
TIMER_A0->CCR[4] = 40000 / 3;

}
else if (ADC14->MEM[0] > 0x2FF & ADC14->MEM[0] <= 0x7FF) {
//P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 20000 - 1;
TIMER_A0->CCR[4] = 20000 / 2;

}

else if (ADC14->MEM[0] > 0x7FF & ADC14->MEM[0] <= 0xAFF) {
//P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 15000 - 1;
TIMER_A0->CCR[4] = 15000 / 1.5;

}
else if (ADC14->MEM[0] > 0xAFF & ADC14->MEM[0] <= 0xCFF) {
// P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
P4->OUT ^= BIT6;
}
P1->IFG &= ~BIT1;
TIMER_A0->CCR[0] = 10000 - 1;
TIMER_A0->CCR[4] = 10000 / 1.2;

}
else if (ADC14->MEM[0] > 0xCFF & ADC14->MEM[0] <= 0xFFF) {
//P1->OUT = ~BIT0;
if (P1->IFG & BIT1) {
if(EUSCI_A0->IFG & EUSCI_A_IFG_RXIFG)
//temp = EUSCI_A0->RXBUF;
EUSCI_A0->IFG &= ~EUSCI_A_IFG_RXIFG;
P4->OUT ^= BIT6;
while(!(EUSCI_A0->IFG & EUSCI_A_IFG_TXIFG));
EUSCI_A0->TXBUF = EUSCI_A0->RXBUF;
EUSCI_A0->TXBUF = "B";

}
P1->IFG &= ~BIT1;

TIMER_A0->CCR[0] = 5000 - 1;
TIMER_A0->CCR[4] = 5000 / 1.1;

}


}

  • Hey,

    I haven't looked through your code, but first, you should probably use the TI high level libraries, that will save you a lot of work. Probably should start from a sample application and keep modifying it. UartEcho perhaps?

    Second, have you looked at the errata for the CPU? The UART is a catastrophe. There are many-many things not working. Interrupts not coming at the right time etc...

    Hope it helps something.

    Cheers,

    Peter

  • Hi Peter,

    Thanks for the reply. I am using a sample code I found online. It is based on a question posted in the TI forum. I have attached the link here. I am not getting the same results as mentioned here. I didn't add the DCO clock as mentioned here because it bricked my device once. I couldn't restore it. So I had to get a new one. I am a beginner when it comes to coding for MSP432.It will be great if you could help me out.

    Here is the link I referred to: e2e.ti.com/.../741392

    I need to fix it asap as the deadline is coming up. 

  • Hi, Balagopal, 

    Could you please start the UART communication with MSP432 UART code examples? 

    This can be found on TI Resource Explorer under the MSP432P4 SDK. 

    Following code examples are in the SDK. 

    msp432p401x_euscia0_uart_01 eUSCI_A0 UART echo at 9600 baud using BRCLK = 12MHz
    msp432p401x_euscia0_uart_03 USCI_A0 External Loopback test @ 115200 baud
    msp432p401x_euscia0_uart_09 USCI_A0 wake up from LPM3 by RxD pin as GPIO interrupt

    Based on the code examples, you can update it for your application code. After checking the clock and UART configuration correct, you can use logic analyzer to capture the UART waveform to debug and address the issue. 

    Thanks, 

    Lixin