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: RS422 protocol and eUSCI_A UART

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hi

I have a device (encoder to measure the rotation velocity of motor shaft), in my application that works with RS422 protocol serial communication and TTL logic. I just need to receive data from the encoder and no transmission from MCU to the encoder is required. I have used EUSCIA3 to account for asynchronous communication. But it is not working. Can you please let me know if I am on the right direction and help me resolve the issue? and also what specifications (baud rate, etc.) are good for the EUSCIA3 given that my signal frequency is variable between 0 and 160kHZ. A snippet of the code is provided below for your review. 

Thanks in advance!

#include "msp.h"

int flag=0;// To check if the reception in ISR is done.
unsigned short RX;//the received data is stored in RX.
long long int i;// Is used in for loop to wait for a while.

void main(void) { WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer //******Pin configurations**********// // Configure UART pins P9->SEL0 |= BIT6; // set 1-UART pin as secondary function P1DIR |=BIT0; // Configure UART EUSCI_A3->CTLW0 |= EUSCI_A_CTLW0_SWRST; // Put eUSCI in reset EUSCI_A3->CTLW0 = EUSCI_A_CTLW0_SWRST | // Remain eUSCI in reset EUSCI_B_CTLW0_SSEL__SMCLK; // Configure eUSCI clock source for SMCLK // Baud Rate calculation // 12000000/(16*9600) = 78.125 // Fractional portion = 0.125 // User's Guide Table 21-4: UCBRSx = 0x10 // UCBRFx = int ( (78.125-78)*16) = 2 EUSCI_A3->BRW = 78; // 12000000/16/9600 EUSCI_A3->MCTLW = (2 << EUSCI_A_MCTLW_BRF_OFS) | EUSCI_A_MCTLW_OS16; EUSCI_A3->CTLW0 &= ~EUSCI_A_CTLW0_SWRST; // Initialize eUSCI EUSCI_A3->IFG &= ~EUSCI_A_IFG_RXIFG; // Clear eUSCI RX interrupt flag // Enable global interrupt __enable_irq(); // Enable eUSCIA0 interrupt in NVIC module NVIC->ISER[0] = 1 << ((EUSCIA3_IRQn) & 31); while (1) { EUSCI_A3->IE |= EUSCI_A_IE_RXIE;// Enable USCI_A0 RX interrupt while(flag==0);// wait until the flag in the ISR become 1. EUSCI_A1->IE &= ~EUSCI_A_IE_RXIE;// Enable USCI_A0 RX interrupt flag=0;//Reset the flag. printf("RX: %d",RX);//print the RX printf("\n");//Go to the next line. for (i=100000;i>1;i--);//wait for a while. } } // UART interrupt service routine void EUSCIA3_IRQHandler(void) { if (EUSCI_A3->IFG & EUSCI_A_IFG_RXIFG) { // Check if the TX buffer is empty first while(!(EUSCI_A3->IFG & EUSCI_A_IFG_TXIFG)); // Echo the received character back RX = EUSCI_A3->RXBUF; P1OUT ^=BIT0; } flag=1; // EUSCI_A1->IFG &= ~EUSCI_A_IFG_RXIFG; }

**Attention** This is a public forum