External interrupt issues

Hi. First let me just say that these Wixels are awesome. The documentation is very straightforward and allowed me to get up and running almost immediately.

I’m working on an application where it would be ideal to be have the chip be in a low power mode (probably LPM2) and to be able to wake the chip up when an external sensor goes high.

First, I thought I should tackle the relatively easy problem of detecting a port interrupt:
But… I’m having problems getting any port interrupt going. Currently I have a button connected to P1_2 that connects that pin to 3.3V when pressed. Below is the code that’s not working: (I modified the example_blink_led app)

/** example_blink_led_with_interrupts app modified with interrupts:
This app blinks the red LED and turns on the yellow LED for 1 second if any pin on port 1 goes high.

For a precompiled version of this app and a tutorial on how to load this app
onto your Wixel, see the Pololu Wixel User's Guide:

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>

int32 CODE param_blink_period_ms = 2000;

uint32 lastToggle = 0;

void updateLeds()

    if (getMs() - lastToggle >= param_blink_period_ms/2)
        lastToggle = getMs();

void putchar(char c)

 ISR(P1INT, 0)

void usbPrint()
	 if (usbComTxAvailable() >= 64) {
		printf("success! \r\n");

void main()
	setPort1PullType(LOW); // enable pull-downs
	P1IEN |= 0x7F; // enable interrupts on port 1


From my understanding the code above should blink the red LED periodically and turn the yellow LED on for 1 second if any pin on Port 1 goes high. But I’m not getting anything happening.

It’s very possible I’m doing something fundamentally wrong. I haven’t worked too much with low level interrupt service routines and port registers.

Any help is greatly appreciated. Thanks!

Hello, langfordw.

I’m glad you are having a good experience with the Wixels!

You should be careful about using Wixel libraries from interrupts. It takes some effort to make a library be interrupt-safe, and if we don’t claim it’s interrupt safe in the documentation then you could have serious problems when you try to use it in an interrupt. For now, I would just turn on the yellow LED in the ISR, or set a bit that the main loop reads.

I recommend making your ISR quicker. The USB specification requires that the device needs to respond to certain USB control transfers within 50 ms, and the Wixel’s USB library won’t be able to do that while your 1-second interrupt is running.

I think the main reason you’re not seeing the yellow LED blink is because you forgot to enable port 1 interrupts by writing “P1IE = 1;”. Also, in your ISR, you will need to clear the interrupt flags. I recommend reading section 12.4.4 (General Purpose I/O Interrupts) of the CC2511 datasheet for information on how to do that properly.