Hello i am trying to compute my EFM32 Controller so it will send me at each clock cycle the number of LEDs that are ON.
I have tried to write the following code shown bellow.its very straight forward inside while(1)
i just increase variable "i" and depending on its value i send a char with that number(UART tx)
but in reality when i fetch in MATLAB what was recieved. Nothing recieved,no chars at all were sent.
Where did i go wrong?
Thanks.
I have tried to write the following code shown bellow.its very straight forward inside while(1)
i just increase variable "i" and depending on its value i send a char with that number(UART tx)
but in reality when i fetch in MATLAB what was recieved. Nothing recieved,no chars at all were sent.
Where did i go wrong?
Thanks.
Code:
#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
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) ;
}
int main(void)
{
int i,j;
i=0;
// Chip errata
CHIP_Init();
// Enable oscillator to GPIO and USART1 modules
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_USART1, true);
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
while (1) ;
}
/* Initialize LED driver */
// BSP_LedsInit();
// BSP_LedSet(0);
GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,1);
GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,1);
// set pin modes for UART TX and RX pins
GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
// GPIO_PinModeSet(LED_PORT_A,15,gpioModePushPull,0);
//GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,0);
// 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)
{
switch ( USART_Rx(USART1))
{
case 'h':
GPIO_PinOutSet(LED_PORT_E,15);
//USART_Tx(USART1,'G');USART_Tx(USART1,'R');USART_Tx(USART1,'E');USART_Tx(USART1,'E');USART_Tx(USART1,'N');USART_Tx(USART1,' ');USART_Tx(USART1,'O');USART_Tx(USART1,'F');USART_Tx(USART1,'F');USART_Tx(USART1,'\n');
i=i-1;
// fprintf(USART1,"LED Green is off\n");
break;
case 'g':
i=i+1;
GPIO_PinOutClear(LED_PORT_E,15);
USART_Tx(USART1,'G');USART_Tx(USART1,'R');USART_Tx(USART1,'E');USART_Tx(USART1,'E');USART_Tx(USART1,'N');USART_Tx(USART1,' ');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'\n');
fprintf(USART1,"LED Green is ON\n");
break;
case 't':
i=i-1;
//GPIO_PinOutSet(LED_PORT_A,15);
//USART_Tx(USART1,'R');USART_Tx(USART1,'E');USART_Tx(USART1,'D');USART_Tx(USART1,' ');USART_Tx(USART1,'O');USART_Tx(USART1,'F');USART_Tx(USART1,'F');USART_Tx(USART1,'\n');
//fprintf(USART1,"LED RED is off\n");
break;
case 'r':
i=i+1;
//fprintf(USART1,"LED RED is ON\n");
//USART_Tx(USART1,'R');USART_Tx(USART1,'E');USART_Tx(USART1,'D');USART_Tx(USART1,' ');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'\n');
//GPIO_PinOutClear(LED_PORT_A,15);
break;
default:
//fprintf(USART1,"NONE\n");
// USART_Tx(USART1,'N');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');USART_Tx(USART1,'\n');
break;
}//end switch
if(i==0)
{
USART_Tx(USART1,'0');
}
if(i==1)
{
USART_Tx(USART1,'1');
}
if(i==2)
{
USART_Tx(USART1,'2');
}
}
}