Other Parts Discussed in Thread: MSP-EXP430FR2311
Tool/software: Code Composer Studio
Hello,
I am just start to do a project with MSP430FR2311, I want to send the ADC result to the PC via UART interface.
I found the data received is garbled. I don't know what the reason is.
#include "driverlib.h"
uint16_t i;
uint8_t RXData = 1, TXData = 1;
uint8_t check = 0;
void main(void)
{
// stop watchdog
WDT_A_hold(WDT_A_BASE);
// XT1 Setup
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P1,
GPIO_PIN7 + GPIO_PIN6,
GPIO_PRIMARY_MODULE_FUNCTION
);
//Set external clock frequency to 32.768 KHz
CS_setExternalClockSource(32768);
//Set ACLK=XT1
CS_initClockSignal(CS_ACLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_1);
//Start XT1 with no time out
CS_turnOnXT1(CS_XT1_DRIVE_0);
//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);
// Configure UART pins
//P1.7-Tx
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P1,
GPIO_PIN7,
GPIO_PRIMARY_MODULE_FUNCTION
);
//P1.6-Rx
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P1,
GPIO_PIN6,
GPIO_PRIMARY_MODULE_FUNCTION
);
/*
* Disable the GPIO power-on default high-impedance mode to activate
* previously configured port settings
*/
PMM_unlockLPM5();
//Configure UART
EUSCI_A_UART_initParam param = {0};
param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
param.clockPrescalar = 8;
param.firstModReg = 0;
param.secondModReg = 6;
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_LOW_FREQUENCY_BAUDRATE_GENERATION;
if(STATUS_FAIL == EUSCI_A_UART_init(EUSCI_A0_BASE, ¶m))
{
return;
}
EUSCI_A_UART_enable(EUSCI_A0_BASE);
EUSCI_A_UART_clearInterrupt(EUSCI_A0_BASE,
EUSCI_A_UART_RECEIVE_INTERRUPT);
// Enable USCI_A0 RX interrupt
EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,
EUSCI_A_UART_RECEIVE_INTERRUPT); // Enable interrupt
__enable_interrupt();
while(1)
{
TXData = TXData + 1; // Increment TX data
// Load data onto buffer
EUSCI_A_UART_transmitData(EUSCI_A0_BASE,
TXData);
while(check != 1)
{
;
}
check = 0;
}
}
//******************************************************************************
//
//This is the USCI_A0 interrupt vector service routine.
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A0_VECTOR)))
#endif
void EUSCI_A0_ISR(void)
{
switch(__even_in_range(UCA0IV,USCI_UART_UCTXCPTIFG))
{
case USCI_NONE: break;
case USCI_UART_UCRXIFG:
RXData = EUSCI_A_UART_receiveData(EUSCI_A0_BASE);
if(!(RXData == TXData)) // Check value
{
while(1)
{
;
}
}
check = 1;
break;
case USCI_UART_UCTXIFG: break;
case USCI_UART_UCSTTIFG: break;
case USCI_UART_UCTXCPTIFG: break;
}
}
This is the result:


