WAKEUP inverted (newbie question)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

WAKEUP inverted (newbie question)

202 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abb on Mon Feb 03 09:26:17 MST 2014
Hello,

I am trying to get an interrupt on USB bus attach/detach events. For this I connect WAKEUP pin to VUSB (P2_5 pin on MCB4357) and to the ground via 22K resistor. It works fine, except the fact that it works up-side-down. I mean, as far as I can tell, when in EVRT_SRC_ACTIVE_HIGH_LEVEL configuration the system generates an IRQ when input level is low, and other way around.

My code is below. I know I must be doing something wrong, but can't figure out what. Any help is appreciated.

PS. I have surrounded my code with code-tag, but somehow it still looses identation...

Best regards,
Alex

<code>
#include "board.h"

static volatile uint32_t systicks = 0;

void SysTick_Handler(void) {
systicks++;
}

#define VUSB_WAKEUP_SRC EVRT_SRC_WAKEUP1

static volatile uint8_t attached_to_host;
static volatile uint32_t nwakeups; // for debugging only

void EVRT_IRQHandler(void) {
if (Chip_EVRT_IsSourceInterrupting(VUSB_WAKEUP_SRC)) {
Chip_EVRT_ClrPendIntSrc(VUSB_WAKEUP_SRC);

if (attached_to_host == 0) {
Chip_EVRT_ConfigIntSrcActiveType(VUSB_WAKEUP_SRC, EVRT_SRC_ACTIVE_LOW_LEVEL);
attached_to_host = 1;
} else {
Chip_EVRT_ConfigIntSrcActiveType(VUSB_WAKEUP_SRC, EVRT_SRC_ACTIVE_HIGH_LEVEL);
attached_to_host = 0;
}
nwakeups++;
// DEBUGOUT("* attached_to_host=%d, nwakeups=%d\r\n", attached_to_host, nwakeups);
}
}

void evrt_init(void) {
Chip_EVRT_Init();
Chip_EVRT_SetUpIntSrc(VUSB_WAKEUP_SRC, ENABLE);
NVIC_SetPriority(EVENTROUTER_IRQn, ((0x01 << 3) | 0x01)); // preemption = 1, sub-priority = 1 FIXME
Chip_EVRT_ConfigIntSrcActiveType(VUSB_WAKEUP_SRC, EVRT_SRC_ACTIVE_HIGH_LEVEL);
attached_to_host = 0;
nwakeups = 0;
NVIC_EnableIRQ(EVENTROUTER_IRQn);
}

int main(void) {
SystemCoreClockUpdate();
Board_Init();
DEBUGOUT("\r\nstarted\r\n");

SysTick_Config(SystemCoreClock/1000);
evrt_init();

for(;;) {
for(systicks=0; systicks<1000; ) {}; // 1s delay
DEBUGOUT("attached_to_host=%d, nwakeups=%d\r\n", attached_to_host, nwakeups);
}
}
</code>

Labels (1)
0 Kudos
0 Replies