/**
 * @file main.c
 * @brief Demo UART echo
 *
 * In this example byte that is received using UART is incremented and sent back
 * to the PC.
 *
 * @date 2019
 * @author Strahinja Jankovic (jankovics@etf.bg.ac.rs)
 *
 * @version [2.0 @ 04/2021] Hardware change
 * @version [1.1 @ 03/2019] Code refactor.
 * @version [1.0 @ 03/2017] Initial version
 */
#include <msp430.h> 

#define BR9600      (3)

/**
 * @brief Main function
 *
 * Demo waits until data is received, modifies it and sends back
 */
int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

    P4SEL |= BIT4 + BIT5;       // select P4.4 and P4.5 for USCI

    // initialize USCI
    UCA1CTL1 |= UCSWRST;        // put USCI in reset

    UCA1CTL0 = 0;               // no parity, 8bit, 1 stop bit
    UCA1CTL1 |= UCSSEL__ACLK;   // use ACLK
    //UCA1BRW = BR9600;         // BR = 3
    UCA1BR0 = 3;
    UCA1BR1 = 0;
    UCA1MCTL |= UCBRS_3 + UCBRF_0;    // BRS = 3 for 9600 bps

    UCA1CTL1 &= ~UCSWRST;       // release reset

    while (1)
    {
        while ((UCA1IFG & UCRXIFG) == 0);       // poll if something is received
        UCA1TXBUF = UCA1RXBUF + 1;              // send received ASCII code + 1
    }
}
