#include "em_device.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"
#include "em_chip.h"
//////////////////////////////////////
#include <stdint.h>
#include <stdbool.h>
#include "em_emu.h"
#include "bsp.h"
#include "bsp_trace.h"
///////////////////////////////////////
#define LED_PORT_E gpioPortE
#define LED_PIN_E 15
#define LED_PORT_A gpioPortA
#define LED_PIN_A 15
#define BUFFER_SIZE 1
char buffer[BUFFER_SIZE];
volatile uint32_t msTicks; /* counts 1ms timeTicks */
void Delay(uint32_t dlyTicks);
void SysTick_Handler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
}
void Delay(uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks) ;
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
int i,j;
// Chip errata
CHIP_Init();
// Enable oscillator to GPIO and USART1 modules
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_USART1, true);
// BSP_TraceProfilerSetup();
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
while (1) ;
}
/* Initialize LED driver */
// set pin modes for UART TX and RX pins
GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
// Initialize USART asynchronous mode and route pins
USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
//init.parity=usartEvenParity;
USART_InitAsync(USART1, &init);
USART1->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN;
while (1)
{
//E-green
//A-red
GPIO_PinOutSet(LED_PORT_E,15);
USART_Tx(USART1,buffer[0]);
GPIO_PinOutClear(LED_PORT_E,15);
if (USART_Rx(USART1) == 'g')
{
GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,0);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');
}
if (USART_Rx(USART1) == 'h')
{
GPIO_PinOutClear(LED_PORT_E,15);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');
}
if (USART_Rx(USART1) == 'r')
{
GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');
}
if (USART_Rx(USART1) == 't')
{
GPIO_PinOutClear(LED_PORT_A,15);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');
}
}
}