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.

MSP430FR2422: UART TRY

Part Number: MSP430FR2422

Hi ,

I am trying to configure the UART Protocol in the MSP430FR2422 . Below is my code attached . I am trying to configure it on P1.4(UCA0TXD) and P1.5(UCA0RXD) . But here i am not able to get anything on my Tera Term screen . After cross checking certain times I am not able to find the difficulty . So it would be helpful if anyone can help.

#include "driverlib.h" // for driver library
#include <msp430.h>

//first we will go through the pin assignament

#define GPIO_PORT_UCA0TXD GPIO_PORT_P1
#define GPIO_PIN_UCA0TXD GPIO_PIN4
#define GPIO_FUNCTION_UCA0TXD GPIO_PRIMARY_MODULE_FUNCTION
#define GPIO_PORT_UCA0RXD GPIO_PORT_P1
#define GPIO_PIN_UCA0RXD GPIO_PIN5
#define GPIO_FUNCTION_UCA0RXD GPIO_PRIMARY_MODULE_FUNCTION

// now we will configure the UART pins using the folloowing function and over here inline because inline function whenever aleed it will replace the main function call with the code which is present at the function call.
//note here that the function is not going to the actual call just it is saving some registers and saving some time which might be benificial.

void inline UCA0UART_GPIOinit(void)
{
//Configure UART pins
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_UCA0TXD,
GPIO_PIN_UCA0TXD,
GPIO_FUNCTION_UCA0TXD
);
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_UCA0RXD,
GPIO_PIN_UCA0RXD,
GPIO_FUNCTION_UCA0RXD
);
}


// now we will use the declaration function
// this function contains the certain parameters which are explained below against their declaration and are necessary for initilixzation
void EUSCI_A0_UARTinit (void)
{
//Configure UART0
//SMCLK = 12MHz, Baudrate = 19200
//LSBfirst, PARITY no, STOP_BITS one
//UCBRx = 39, UCBRFx = 1, UCBRSx = 0x00, UCOS16 = 1 (overSampling = 1)
EUSCI_A_UART_initParam param = {0};
param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
param.clockPrescalar = 39;
param.firstModReg = 1;
param.secondModReg = 0x00;
param.parity = EUSCI_A_UART_NO_PARITY;
param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
param.uartMode = EUSCI_A_UART_MODE;
param.overSampling = EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
if (STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, &param)) {
return;
}
//enabling the base address first
EUSCI_A_UART_enable(EUSCI_A0_BASE);

//then we will clear the first
EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
EUSCI_A_UART_TRANSMIT_INTERRUPT);

// Enable USCI_A0 RX interrupt
EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
EUSCI_A_UART_TRANSMIT_INTERRUPT);
}
const uint8_t TXbuffer0[40] = "UART0 sample message 115200\n\r"; // constant as it size would be fix and
volatile uint8_t UART0_byteCounter = 0; // volatile for fast memory access which is sometimes required.

// now it main fuction declaration
int main(void) {

WDT_A_hold(WDT_A_BASE);

UCA0UART_GPIOinit();

PMM_unlockLPM5();
// now we need to add the clock in main

CS_initClockSignal(CS_ACLK,CS_REFOCLK_SELECT,CS_CLOCK_DIVIDER_1);
//Set SMCLK = DCO with frequency divider of 1
CS_initClockSignal(CS_SMCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);
//Set MCLK = DCO with frequency divider of 1
CS_initClockSignal(CS_MCLK,CS_DCOCLKDIV_SELECT,CS_CLOCK_DIVIDER_1);

EUSCI_A0_UARTinit();

// Enable global interrupts
__enable_interrupt();
while (1)

{
unsigned long int i;
if(UART0_byteCounter==0)
{
for(i=0;i<100000;i++);
UART0_byteCounter=1; // for reseting the value so unless there is no data coming it will contiue in the loop so that the tx buffer will be pass to rx buffer
UCA0TXBUF=TXbuffer0[0];
}
}
}

// now we will write the interrupt service routine if that we if we send some data then the data should receive first

#pragma vector=USCI_A0_VECTOR
__interrupt
void EUSCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG: break; //Receive buffer full
case USCI_UART_UCTXIFG: //Transmit buffer empty
{
if (TXbuffer0[UART0_byteCounter] != 0)
{
UCA0TXBUF = TXbuffer0[UART0_byteCounter];
UART0_byteCounter++;
}
else
{
UART0_byteCounter = 0;
//__bic_SR_register_on_exit(LPM3_bits);
}

}
break;
case USCI_UART_UCSTTIFG: break; //Start bit received
case USCI_UART_UCTXCPTIFG: break; //Transmit complete
}
}

**Attention** This is a public forum