Other Parts Discussed in Thread: MSP-EXP430FR4133, ENERGIA, MSP430FR4133
Tool/software: Code Composer Studio
Hi,
I am Using MSP-EXP430FR4133 launchpad. I am able to get Uart TX and RX in Energia but in Code composer studio, I have tried the API provided in the library and also i Have tried programs using Registers. I am not able to get it done. I have attached the code below. Can anyone help?
SOURCE CODE.
#include"msp430fr4133.h"
#include<stdio.h>
#include"eusci_a_uart.h"
#define TXD BIT0
#define RXD BIT1
void init_gpio();
void main()
{
uint8_t txdata;
uint8_t rxdata;
int status;
volatile unsigned int j;
volatile unsigned int i;
//******************* starting point **************************//
// --------------------------------------------------------------//
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
init_gpio(); // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
EUSCI_A_UART_initParam my_uart_param; // we need to declare an instance of strcutre so that we can assign the parameter to this structure
my_uart_param.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK; //for peripheral work
my_uart_param.clockPrescalar = 104; // set baud rate with 16 MHz clock
my_uart_param.firstModReg = 2;
my_uart_param.secondModReg = 0xd6;
my_uart_param.parity = EUSCI_A_UART_NO_PARITY;
my_uart_param.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
my_uart_param.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
my_uart_param.uartMode = EUSCI_A_UART_MODE;
my_uart_param.overSampling = EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
EUSCI_A_UART_initParam *ptr_my_uart = & my_uart_param;
P1SEL0 |=(BIT0 |BIT1);
P1DIR = BIT0; // P1.1 = RXD, P1.2=TXD
EUSCI_A_UART_disable(EUSCI_A0_BASE);//step1 in initialization process
EUSCI_A_UART_init(EUSCI_A0_BASE,ptr_my_uart); // step2 initialization
// UCA0STATW |= UCLISTEN ; // loopback mode
EUSCI_A_UART_enable(EUSCI_A0_BASE); // Reset the UCSWRST bit to enable the USCI Module
//EUSCI_A_UART_enableInterrupt(EUSCI_A0_BASE,(EUSCI_A_UART_RECEIVE_INTERRUPT | EUSCI_A_UART_TRANSMIT_INTERRUPT| EUSCI_A_UART_STARTBIT_INTERRUPT| EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT) );
while(1)
{
txdata ^= 0x10;
EUSCI_A_UART_transmitData(EUSCI_A0_BASE,txdata); // transmit the data;
while(!( EUSCI_A_UART_getInterruptStatus(EUSCI_A0_BASE,EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG)))
{
;
}
rxdata = EUSCI_A_UART_receiveData(EUSCI_A0_BASE); // store the received data in a variable .The RXIFG flags automatically reset when RXBUF is read
if(rxdata==0x10)
{
status=1;
}
else
{
status=2;
}
switch(status)
{
case 1: P4DIR|=0x01;
for(i=1000;i>0;i--)
{
P4OUT=0x01;
}
P4OUT=0x00;
break;
case 2: P4DIR|=0x00;
for(i=5000;i>0;i--)
{
P4OUT=0x00;
}
break;
}
}
}
void init_gpio(void)
{
// Configure all GPIO to Output Low
// Make sure there is no pin conflict with respect to schematic
P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00;
P5OUT = 0x00; P6OUT = 0x00; P7OUT = 0x00; P8OUT = 0x00;
P1DIR = 0xFD; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF;
P5DIR = 0xFD; P6DIR = 0xFF; P7DIR = 0xFF; P8DIR = 0xFF;
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings for low power mode5
}
Is there any other source code for UART.. ?