***********************************************************************************
***
* Description: This code uses usart. Receives a string ending in / n or / r. It
also
* turns a led on and off when the string "led \ r" is received.
*
* Pins:
* - 1.0: Led
* - 1.1: Rx UART
* - 1.2: Tx UART
*
* Author : Matias Sepulveda Pradenas
* Email : mesepulveda@uc.cl
* Last modification date : 30/04/17
***********************************************************************************
**/
/************************************** Includes
**************************************/
#include <msp430g2553.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "UART/UART.h"
/************************************** Includes
**************************************/
/*************************************** UART.c
***************************************/
// Rx Interrupt: Receive a character and add it to the buffer
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void){
char letra = UCA0RXBUF;
add_to_list(letra, "rx");
}
/*************************************** PORTS
***************************************/
// All pins as inputs, except 1.0. (UART pins are automatically set up)
void init_ports(void){
P1DIR = 0x00;
P1REN = 0x00;
P1OUT = 0x00;
P2DIR = 0x00;
P2REN = 0x00;
P2OUT = 0x00;
P3DIR = 0x00;
P2REN = 0x00;
P3OUT = 0x00;
P1DIR |= (1 << 0); // 1.0 output
}
/*************************************** PORTS
***************************************/
/*************************************** CLOCK
***************************************/
// Clock to 16MHz
void init_clock(void){
DCOCTL = CALDCO_16MHZ; // Calibrate DCO to 16MHz
BCSCTL1 = CALBC1_16MHZ; // Calibrate system clock to 16MHz
BCSCTL2 &= ~SELS; // Select DCOCLK as SMCLK
}
/*************************************** CLOCK
***************************************/
/*************************************** MAIN
***************************************/
int main(void){
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog timer
while(1){
USART_Receive_String(string, 50);
if (strlen(string)){
if (strcmp(string, "led\r") == 0){
P1OUT ^= (1 << 0);
}
USART_Transmit_String("Received: ");
USART_Transmit_String(string);
USART_Transmit_String("\n");
}
}
}
/*************************************** MAIN
***************************************/