yefj
Advanced Member level 5
Hello,I had a phenomena where when i defined my LED they turned on by defualt as starting point.
I didnt want that, so i made sure the OUT in the GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,0) is zero.
But the opposite happened and it turned them on by default.
When i made out=1 it turned it off on starting point,but when i did GPIO_PinOutSet(LED_PORT_E,15); it actualy turned off the LED instead of turning on.
the same thing happaned with
It turned on the led instead of turning it off.I tried to look at the GPIO API shown bellow.
Why it has this opposite behavior when i do in GPIO pinmodeset out=1?
The full code is shown bellow.
Thanks.
I didnt want that, so i made sure the OUT in the GPIO_PinModeSet(LED_PORT_E,15,gpioModePushPull,0) is zero.
But the opposite happened and it turned them on by default.
When i made out=1 it turned it off on starting point,but when i did GPIO_PinOutSet(LED_PORT_E,15); it actualy turned off the LED instead of turning on.
the same thing happaned with
Code:
GPIO_PinOutClear(LED_PORT_E,15);
Why it has this opposite behavior when i do in GPIO pinmodeset out=1?
The full code is shown bellow.
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
#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) ;
}
int main(void)
{
// 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 */
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);
USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
USART_InitAsync(USART1, &init);
USART1->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN;
while (1)
{
//E-green
//A-red
switch ( USART_Rx(USART1))
{
case 'g':
GPIO_PinOutSet(LED_PORT_E,15);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');USART_Tx(USART1,'\n');
break;
case 'h':
GPIO_PinOutClear(LED_PORT_E,15);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');USART_Tx(USART1,'\n');
break;
case 'r':
GPIO_PinOutSet(LED_PORT_A,15);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');USART_Tx(USART1,'\n');
break;
case 't':
GPIO_PinOutSet(LED_PORT_A,15);
GPIO_PinOutClear(LED_PORT_A,15);
USART_Tx(USART1,'D');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');USART_Tx(USART1,'\n');
break;
default:
USART_Tx(USART1,'N');USART_Tx(USART1,'O');USART_Tx(USART1,'N');USART_Tx(USART1,'E');USART_Tx(USART1,'\n');
break;
}//end switch
}
}