9 years, 3 months ago.

Issue with Interrupts and MPR121 Capacitive Touch Sensor

Hello all. I am new to programming micro controllers and a class project requires me to use the Nucleo F767 board. I am using the Freescale MPR121 capacitive touch sensor and got the sensor working using a hello world program I found. I am now trying to modify it to use interrupts instead of continuously checking the electrode status registers but am having difficulty reading the registers. The following code functions perfectly, the three LEDs light up based on which electrodes have been touched:

  1. include "mbed.h"
  2. include "MPR121.h"

Serial pc(USBTX, USBRX); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3);

/if defined TARGET_LPC1768 || TARGET_LPC11U24 I2C i2c(PB_9, PB_8); InterruptIn irq(PF_12); MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);

void checkPads() {

uint8_t value = touch_pad.readRegister(MPR121::ELE0_7_STAT);

if(value % 2 == 0) led1 = 0; else led1 = 1;

if(value % 4 < 2) led2 = 0; else led2 = 1;

if(value % 8 < 4) led3 = 0; else led3 = 1; }

void fallInterrupt() { }

int main() { touch_pad.init(); touch_pad.enable(); irq.fall(fallInterrupt); irq.mode(PullUp);

while (1) {checkPads();} }

However when I move the checkPads(); statement to the fallInterrupt() function, the registers only read zero. I know for a fact that the fallInterrupt function is called correctly, as I have modified the code before to light the LEDs for a period of time when an interrupt occurs. I have not been able to determine why moving the checkPads statement to the interrupt block prevents it from functioning properly. Any help would be appreciated.

/media/uploads/Black_Electric/mpr121.zip

Be the first to answer this question.